1 #pragma once 2 3 #include <sstream> 4 5 #include <rapidcheck.h> 6 #include <catch2/catch.hpp> 7 8 namespace rc { 9 10 /// For use with `catch2/catch.hpp`. Use this function wherever you would use a 11 /// `SECTION` for convenient checking of properties. 12 /// 13 /// @param description A description of the property. 14 /// @param testable The object that implements the property. 15 template <typename Testable> prop(const std::string & description,Testable && testable)16void prop(const std::string &description, Testable &&testable) { 17 using namespace detail; 18 19 #ifdef CATCH_CONFIG_PREFIX_ALL 20 CATCH_SECTION(description) { 21 #else 22 SECTION(description) { 23 #endif 24 25 const auto result = checkTestable(std::forward<Testable>(testable)); 26 27 if (result.template is<SuccessResult>()) { 28 const auto success = result.template get<SuccessResult>(); 29 if (!success.distribution.empty()) { 30 std::cout << "- " << description << std::endl; 31 printResultMessage(result, std::cout); 32 std::cout << std::endl; 33 } 34 } else { 35 std::ostringstream ss; 36 printResultMessage(result, ss); 37 #ifdef CATCH_CONFIG_PREFIX_ALL 38 CATCH_INFO(ss.str() << "\n"); 39 CATCH_FAIL(); 40 #else 41 INFO(ss.str() << "\n"); 42 FAIL(); 43 #endif 44 } 45 } 46 } 47 48 } // namespace rc 49