1 #include <catch2/catch.hpp> 2 #include <rapidcheck/catch.h> 3 4 using namespace rc; 5 using namespace rc::detail; 6 7 struct TagCollector : public PropertyContext { reportResultTagCollector8 bool reportResult(const CaseResult &) override { return false; } logStreamTagCollector9 std::ostream &logStream() override { RC_FAIL("Shouldn't be called"); } addTagTagCollector10 void addTag(std::string str) override { tags.push_back(std::move(str)); } 11 12 std::vector<std::string> tags; 13 }; 14 15 TEST_CASE("RC_CLASSIFY") { 16 SECTION("uses condition as tag if none specified") { 17 TagCollector collector; 18 ImplicitParam<param::CurrentPropertyContext> letContext(&collector); 19 RC_CLASSIFY(10 > 1); 20 REQUIRE(collector.tags == std::vector<std::string>{"10 > 1"}); 21 } 22 23 SECTION("does not tag if condition is false") { 24 TagCollector collector; 25 ImplicitParam<param::CurrentPropertyContext> letContext(&collector); 26 RC_CLASSIFY(false); 27 REQUIRE(collector.tags.empty()); 28 } 29 30 prop("uses tags if provided", __anon840ece3b0102(const std::string &tag1, int tag2) 31 [](const std::string &tag1, int tag2) { 32 TagCollector collector; 33 ImplicitParam<param::CurrentPropertyContext> letContext(&collector); 34 RC_CLASSIFY(true, tag1, tag2); 35 RC_ASSERT(collector.tags == 36 (std::vector<std::string>{toString(tag1), toString(tag2)})); 37 }); 38 } 39 40 TEST_CASE("RC_TAG") { 41 prop("adds given tags", __anon840ece3b0202(const std::string &tag1, int tag2) 42 [](const std::string &tag1, int tag2) { 43 TagCollector collector; 44 ImplicitParam<param::CurrentPropertyContext> letContext(&collector); 45 RC_TAG(tag1, tag2); 46 RC_ASSERT(collector.tags == 47 (std::vector<std::string>{toString(tag1), toString(tag2)})); 48 }); 49 } 50