Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: '^<(catch|nanobench).*>'
- Regex: '^<(doctest|nanobench).*>'
Priority: 1
SortPriority: 1
Comment thread
AlexInLog marked this conversation as resolved.
- Regex: '^<rpp/.*/fwd.hpp>'
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_ENABLE_COVERAGE)
add_test(NAME ${TARGET} COMMAND ${CMAKE_COMMAND} -E env LLVM_PROFILE_FILE=${RPP_TEST_RESULTS_DIR}/${TARGET}.profraw $<TARGET_FILE:${TARGET}> -v high)
add_test(NAME ${TARGET} COMMAND ${CMAKE_COMMAND} -E env LLVM_PROFILE_FILE=${RPP_TEST_RESULTS_DIR}/${TARGET}.profraw $<TARGET_FILE:${TARGET}>)
else()
add_test(NAME ${TARGET} COMMAND $<TARGET_FILE:${TARGET}> -v high -s)
add_test(NAME ${TARGET} COMMAND $<TARGET_FILE:${TARGET}>)
endif()
endmacro()
endif()
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,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.
- [catch](https://github.com/catchorg/Catch2) for unit testing only, fetched automatically in case of `RPP_BUILD_TESTS` enabled
- [doctest](https://github.com/doctest/doctest) 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
2 changes: 1 addition & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ endif()

# ===================== Tests ===================
if (RPP_BUILD_TESTS)
rpp_fetch_library(Catch2 https://github.com/catchorg/Catch2.git v3.6.0)
rpp_fetch_library(doctest https://github.com/doctest/doctest.git v2.4.11)
Comment thread
AlexInLog marked this conversation as resolved.
rpp_fetch_library(trompeloeil https://github.com/rollbear/trompeloeil.git main)
endif()

Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RppConan(ConanFile):
def requirements(self):
if self.options.with_tests:
self.requires("trompeloeil/47")
self.requires("catch2/3.6.0")
self.requires("doctest/2.4.11")

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,5 +8,5 @@ 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.*catch
sonar.issue.ignore.allfile.a1.fileRegexp=#include.*doctest
sonar.cfamily.compile-commands=build/compile_commands.json
3 changes: 1 addition & 2 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ macro(add_test_target target_name module files)
set(TARGET ${target_name})

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

add_test_with_coverage(${TARGET})
Expand Down
25 changes: 12 additions & 13 deletions src/tests/rpp/test_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
// Project home: https://github.com/victimsnino/ReactivePlusPlus
//

#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <doctest/doctest.h>

#include <rpp/observables/dynamic_observable.hpp>
#include <rpp/operators/buffer.hpp>
Expand All @@ -25,10 +24,10 @@ TEST_CASE("buffer bundles items")
trompeloeil::sequence s{};
auto mock = mock_observer<std::vector<int>>{};

SECTION("observable of -1-2-3-|")
SUBCASE("observable of -1-2-3-|")
{
auto obs = rpp::source::just(1, 2, 3);
SECTION("buffer(0) - shall see -{1}-{2}-{3}-|")
SUBCASE("buffer(0) - shall see -{1}-{2}-{3}-|")
{
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{1})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{2})).IN_SEQUENCE(s);
Expand All @@ -37,7 +36,7 @@ TEST_CASE("buffer bundles items")

obs | rpp::ops::buffer(0) | rpp::ops::subscribe(mock);
}
SECTION("buffer(1) - shall see -{1}-{2}-{3}-|")
SUBCASE("buffer(1) - shall see -{1}-{2}-{3}-|")
{
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{1})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{2})).IN_SEQUENCE(s);
Expand All @@ -47,7 +46,7 @@ TEST_CASE("buffer bundles items")
obs | rpp::ops::buffer(1)
| rpp::ops::subscribe(mock);
}
SECTION("buffer(2) - shall see -{1,2}-{3}|")
SUBCASE("buffer(2) - shall see -{1,2}-{3}|")
{
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);
Expand All @@ -56,15 +55,15 @@ TEST_CASE("buffer bundles items")
obs | rpp::ops::buffer(2)
| rpp::ops::subscribe(mock);
}
SECTION("buffer(3) - shall see -{1,2,3}-|")
SUBCASE("buffer(3) - shall see -{1,2,3}-|")
{
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}-|")
SUBCASE("buffer(4) - shall see -{1,2,3}-|")
{
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{1, 2, 3})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_completed()).IN_SEQUENCE(s);
Expand All @@ -74,37 +73,37 @@ TEST_CASE("buffer bundles items")
}
}

SECTION("observable of -1-x-2-|, which error is raised in the middle")
SUBCASE("observable of -1-x-2-|, which error is raised in the middle")
{
auto obs = rpp::source::just(rpp::source::just(1).as_dynamic(),
rpp::source::error<int>(std::make_exception_ptr(std::runtime_error{""})).as_dynamic(),
rpp::source::just(2).as_dynamic())
| rpp::ops::merge();
SECTION("buffer(0) - shall see -{1}-x, which means error event is through")
SUBCASE("buffer(0) - shall see -{1}-x, which means error event is through")
{
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")
SUBCASE("buffer(1) - shall see -{1}-x, which means error event is through")
{
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)
| rpp::ops::subscribe(mock);
}
SECTION("buffer(2) - shall see --x, which means error event is through")
SUBCASE("buffer(2) - shall see --x, which means error event is through")
{
REQUIRE_CALL(*mock, on_error(trompeloeil::_)).IN_SEQUENCE(s);

obs | rpp::ops::buffer(2)
| rpp::ops::subscribe(mock);
}
}
SECTION("accept by moving")
SUBCASE("accept by moving")
{
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{1, 2})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{3, 4})).IN_SEQUENCE(s);
Expand Down
15 changes: 7 additions & 8 deletions src/tests/rpp/test_combine_latest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
// Project home: https://github.com/victimsnino/ReactivePlusPlus
//

#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <doctest/doctest.h>

#include <rpp/operators/as_blocking.hpp>
#include <rpp/operators/combine_latest.hpp>
Expand All @@ -26,7 +25,7 @@

TEST_CASE("combine_latest bundles items")
{
SECTION("observable of -1-2-3-| combines with -4-5-6-| on immediate scheduler")
SUBCASE("observable of -1-2-3-| combines with -4-5-6-| on immediate scheduler")
{
auto mock = mock_observer<std::tuple<int, int>>{};
trompeloeil::sequence seq;
Expand All @@ -41,7 +40,7 @@ TEST_CASE("combine_latest bundles items")
| rpp::ops::subscribe(mock);
}

SECTION("observable of -1-2-3-| combines with -4-5-6-| on current_thread")
SUBCASE("observable of -1-2-3-| combines with -4-5-6-| on current_thread")
{
auto mock = mock_observer<std::tuple<int, int>>{};
trompeloeil::sequence seq;
Expand All @@ -62,7 +61,7 @@ TEST_CASE("combine_latest bundles items")
// source 2: -4---5---6-|
}

SECTION("observable of -1-2-3-| combines with two other sources on current_thread")
SUBCASE("observable of -1-2-3-| combines with two other sources on current_thread")
{
auto mock = mock_observer<std::tuple<int, int, int>>{};
trompeloeil::sequence seq;
Expand Down Expand Up @@ -91,7 +90,7 @@ TEST_CASE("combine_latest bundles items")

TEST_CASE("combine_latest defers completed event")
{
SECTION("observable of -1-2-3-| and never")
SUBCASE("observable of -1-2-3-| and never")
{
auto mock = mock_observer<std::tuple<int, int>>{};

Expand All @@ -103,7 +102,7 @@ TEST_CASE("combine_latest defers completed event")

TEST_CASE("combine_latest forwards errors")
{
SECTION("observable of -1-2-3-| combines with error")
SUBCASE("observable of -1-2-3-| combines with error")
{
auto mock = mock_observer<std::tuple<int, int>>{};
REQUIRE_CALL(*mock, on_error(trompeloeil::_));
Expand All @@ -115,7 +114,7 @@ TEST_CASE("combine_latest forwards errors")

TEST_CASE("combine_latest handles race condition")
{
SECTION("suscribe on source observable in current thread pairs with error in other thread - on_error can't interleave with on_next")
SUBCASE("suscribe on source observable in current thread pairs with error in other thread - on_error can't interleave with on_next")
{
auto subject = rpp::subjects::publish_subject<int>{};
auto mock = mock_observer<std::tuple<int, int>>{};
Expand Down
39 changes: 19 additions & 20 deletions src/tests/rpp/test_concat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
// Project home: https://github.com/victimsnino/ReactivePlusPlus
//

#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <doctest/doctest.h>

#include <rpp/disposables/composite_disposable.hpp>
#include <rpp/disposables/disposable_wrapper.hpp>
Expand Down Expand Up @@ -69,12 +68,12 @@ struct my_container_with_error_on_increment
rpp::dynamic_observable<int> m_obs = rpp::source::just(1).as_dynamic();
};

TEMPLATE_TEST_CASE("concat", "", rpp::memory_model::use_stack, rpp::memory_model::use_shared)
TEST_CASE_TEMPLATE("concat", TestType, rpp::memory_model::use_stack, rpp::memory_model::use_shared)
{
mock_observer<int> mock{};
trompeloeil::sequence s{};
auto test = [&](const auto& make_concat) {
SECTION("concat of solo observable")
SUBCASE("concat of solo observable")
{
REQUIRE_CALL(*mock, on_next_lvalue(1)).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_lvalue(2)).IN_SEQUENCE(s);
Expand All @@ -83,7 +82,7 @@ TEMPLATE_TEST_CASE("concat", "", rpp::memory_model::use_stack, rpp::memory_model
auto observable = make_concat(rpp::source::just<TestType>(1, 2));
observable.subscribe(mock);
}
SECTION("concat of multiple same observables")
SUBCASE("concat of multiple same observables")
{
REQUIRE_CALL(*mock, on_next_lvalue(1)).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_lvalue(2)).IN_SEQUENCE(s);
Expand All @@ -94,7 +93,7 @@ TEMPLATE_TEST_CASE("concat", "", rpp::memory_model::use_stack, rpp::memory_model
auto observable = make_concat(rpp::source::just<TestType>(1, 2), rpp::source::just<TestType>(1, 2));
observable.subscribe(mock);
}
SECTION("concat of multiple different observables")
SUBCASE("concat of multiple different observables")
{
REQUIRE_CALL(*mock, on_next_lvalue(1)).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_lvalue(2)).IN_SEQUENCE(s);
Expand All @@ -104,7 +103,7 @@ TEMPLATE_TEST_CASE("concat", "", rpp::memory_model::use_stack, rpp::memory_model
auto observable = make_concat(rpp::source::just<TestType>(1, 2), rpp::source::just<TestType>(1));
observable.subscribe(mock);
}
SECTION("concat stop if no completion")
SUBCASE("concat stop if no completion")
{
REQUIRE_CALL(*mock, on_next_lvalue(1)).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_lvalue(2)).IN_SEQUENCE(s);
Expand All @@ -115,27 +114,27 @@ TEMPLATE_TEST_CASE("concat", "", rpp::memory_model::use_stack, rpp::memory_model

REQUIRE(observer.has_value());

SECTION("send completion later")
SUBCASE("send completion later")
{
REQUIRE_CALL(*mock, on_next_lvalue(3)).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_completed()).IN_SEQUENCE(s);

observer->on_completed();
}
SECTION("send emission later")
SUBCASE("send emission later")
{
REQUIRE_CALL(*mock, on_next_rvalue(10)).IN_SEQUENCE(s);

observer->on_next(10);
}
SECTION("send error later")
SUBCASE("send error later")
{
REQUIRE_CALL(*mock, on_error(trompeloeil::_)).IN_SEQUENCE(s);

observer->on_error({});
}
}
SECTION("concat stoped if disposed")
SUBCASE("concat stoped if disposed")
{
REQUIRE_CALL(*mock, on_next_lvalue(1)).IN_SEQUENCE(s);

Expand All @@ -148,7 +147,7 @@ TEMPLATE_TEST_CASE("concat", "", rpp::memory_model::use_stack, rpp::memory_model
observable.subscribe(rpp::composite_disposable_wrapper{d}, mock);
}

SECTION("concat tracks actual upstream")
SUBCASE("concat tracks actual upstream")
{
auto d = rpp::composite_disposable_wrapper::make();
auto d1 = rpp::composite_disposable_wrapper::make();
Expand All @@ -167,7 +166,7 @@ TEMPLATE_TEST_CASE("concat", "", rpp::memory_model::use_stack, rpp::memory_model
observable.subscribe(rpp::composite_disposable_wrapper{d}, mock);
}

SECTION("concat tracks actual upstream for 2 upstreams")
SUBCASE("concat tracks actual upstream for 2 upstreams")
{
auto d = rpp::composite_disposable_wrapper::make();
auto d1 = rpp::composite_disposable_wrapper::make();
Expand All @@ -192,12 +191,12 @@ TEMPLATE_TEST_CASE("concat", "", rpp::memory_model::use_stack, rpp::memory_model
}
};

SECTION("concat as source")
SUBCASE("concat as source")
{
test([](auto&&... vals) {
return rpp::source::concat<TestType>(std::forward<decltype(vals)>(vals)...);
});
SECTION("concat of array of different observables")
SUBCASE("concat of array of different observables")
{
REQUIRE_CALL(*mock, on_next_lvalue(1)).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_lvalue(2)).IN_SEQUENCE(s);
Expand All @@ -208,21 +207,21 @@ TEMPLATE_TEST_CASE("concat", "", rpp::memory_model::use_stack, rpp::memory_model
auto observable = rpp::source::concat<TestType>(std::array{rpp::source::just<TestType>(1, 2), rpp::source::just<TestType>(1, 1)});
observable.subscribe(mock);
}
SECTION("container with error on begin")
SUBCASE("container with error on begin")
{
REQUIRE_CALL(*mock, on_error(trompeloeil::_)).IN_SEQUENCE(s);

rpp::source::concat<TestType>(my_container_with_error{}).subscribe(mock);
}

SECTION("container with error on increment")
SUBCASE("container with error on increment")
{
REQUIRE_CALL(*mock, on_error(trompeloeil::_)).IN_SEQUENCE(s);

rpp::source::concat<TestType>(my_container_with_error_on_increment{}).subscribe(mock);
}
}
SECTION("concat as operator")
SUBCASE("concat as operator")
{
test([](auto&&... vals) {
return rpp::source::just(std::forward<decltype(vals)>(vals).as_dynamic()...) | rpp::ops::concat();
Expand Down Expand Up @@ -270,7 +269,7 @@ TEST_CASE("concat doesn't produce extra copies")
auto initial_copy = tracker.get_copy_count();
auto initial_move = tracker.get_move_count();

SECTION("pass source via copy")
SUBCASE("pass source via copy")
{
rpp::source::concat(source) | rpp::ops::subscribe([](const copy_count_tracker&) {});
CHECK(tracker.get_copy_count() - initial_copy == 2); // 1 copy to observable + 1 copy to observer
Expand All @@ -285,7 +284,7 @@ TEST_CASE("concat of iterable doesn't produce extra copies")
auto initial_copy = tracker.get_copy_count();
auto initial_move = tracker.get_move_count();

SECTION("pass source via copy")
SUBCASE("pass source via copy")
{
rpp::source::concat(source) | rpp::ops::subscribe([](const copy_count_tracker&) {});
CHECK(tracker.get_copy_count() - initial_copy == 2); // 1 copy to observable + 1 copy to observer
Expand Down
Loading