diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index ebe2f2f7..f14ffc8c 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -4,11 +4,26 @@ ########## +# Install Catch2 + +include( FetchContent ) + +FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.7.1 +) + +FetchContent_MakeAvailable( Catch2 ) +list( APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras ) + +########## + #set( testing_HEADERS #) set( testing_SOURCES - use_catch.cc + run_dl_tests.cc test_agent.cc test_amqp.cc test_core.cc @@ -27,7 +42,6 @@ set( testing_SOURCES set( testing_LIBS Dripline - Catch ) if( Dripline_BUILD_EXAMPLES ) @@ -42,21 +56,21 @@ if( Dripline_BUILD_EXAMPLES ) ) endif() -# Interface library was recommended for Catch: -# https://stackoverflow.com/questions/34896891/catch-lib-unit-testing-and-ctest-cmake-integration/34900012#34900012 -add_library( Catch INTERFACE ) -target_include_directories( Catch INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/catch ) - pbuilder_executable( EXECUTABLE run_dl_tests SOURCES ${testing_SOURCES} PROJECT_LIBRARIES ${testing_LIBS} + PRIVATE_EXTERNAL_LIBRARIES Catch2::Catch2 ) -target_link_libraries( run_dl_tests PUBLIC Catch ) list( APPEND programs "run_dl_tests" ) -message(STATUS "##### programs: ${programs}") +pbuilder_component_install_and_export( + COMPONENT Catch2 + LIBTARGETS Catch2 + NAMESPACE Catch2:: +) + pbuilder_component_install_and_export( COMPONENT Executables EXETARGETS ${programs} diff --git a/testing/run_dl_tests.cc b/testing/run_dl_tests.cc new file mode 100644 index 00000000..86037f77 --- /dev/null +++ b/testing/run_dl_tests.cc @@ -0,0 +1,20 @@ +/* + * run_dl_tests.cc + * + * Created on: Oct 10, 2024 + * Author: N.S. Oblath + */ + + +#include "catch2/catch_session.hpp" + +#include "logger.hh" + +int main( int argc, char* argv[] ) { + + int result = Catch::Session().run( argc, argv ); + + STOP_LOGGING; + + return result; +} diff --git a/testing/test_agent.cc b/testing/test_agent.cc index b6ff8867..13ee46f9 100644 --- a/testing/test_agent.cc +++ b/testing/test_agent.cc @@ -12,7 +12,8 @@ //#include "logger.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" +#include "catch2/matchers/catch_matchers_all.hpp" //LOGGER( talog, "test_agent" ); diff --git a/testing/test_amqp.cc b/testing/test_amqp.cc index 1b0a8d42..68897a92 100644 --- a/testing/test_amqp.cc +++ b/testing/test_amqp.cc @@ -7,7 +7,7 @@ #include "amqp.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" TEST_CASE( "amqp_table", "[amqp]" ) { diff --git a/testing/test_core.cc b/testing/test_core.cc index 104a9928..ad01962d 100644 --- a/testing/test_core.cc +++ b/testing/test_core.cc @@ -14,7 +14,7 @@ #include "authentication.hh" #include "param_codec.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" #include diff --git a/testing/test_dripline_error.cc b/testing/test_dripline_error.cc index d15b9431..a49719bb 100644 --- a/testing/test_dripline_error.cc +++ b/testing/test_dripline_error.cc @@ -11,7 +11,7 @@ #include "logger.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" LOGGER( testlog, "test_dripline_error" ); diff --git a/testing/test_endpoint.cc b/testing/test_endpoint.cc index b09c0430..4ea62d1c 100644 --- a/testing/test_endpoint.cc +++ b/testing/test_endpoint.cc @@ -8,7 +8,7 @@ #include "dripline_exceptions.hh" #include "endpoint.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" TEST_CASE( "submit_msg", "[endpoint]" ) { diff --git a/testing/test_examples_oscillator.cc b/testing/test_examples_oscillator.cc index 41775eb0..4637f93d 100644 --- a/testing/test_examples_oscillator.cc +++ b/testing/test_examples_oscillator.cc @@ -7,7 +7,8 @@ #include "oscillator.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" +#include "catch2/matchers/catch_matchers_all.hpp" #include diff --git a/testing/test_lockout.cc b/testing/test_lockout.cc index b9af45ea..0ff57d52 100644 --- a/testing/test_lockout.cc +++ b/testing/test_lockout.cc @@ -7,7 +7,7 @@ #include "endpoint.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" TEST_CASE( "lockout", "[endpoint]" ) // even though a service is used here for convenience, lockout functionality lives in endpoint diff --git a/testing/test_messages.cc b/testing/test_messages.cc index c0970072..647ca624 100644 --- a/testing/test_messages.cc +++ b/testing/test_messages.cc @@ -9,7 +9,7 @@ #include "logger.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" LOGGER( testlog, "test_message" ); diff --git a/testing/test_return_codes.cc b/testing/test_return_codes.cc index d0a76e4b..cb486942 100644 --- a/testing/test_return_codes.cc +++ b/testing/test_return_codes.cc @@ -11,7 +11,7 @@ #include "logger.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" #include #include diff --git a/testing/test_scheduler.cc b/testing/test_scheduler.cc index 00162f67..e7d32424 100644 --- a/testing/test_scheduler.cc +++ b/testing/test_scheduler.cc @@ -9,7 +9,7 @@ #include "logger.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" #include diff --git a/testing/test_service.cc b/testing/test_service.cc index 6f837465..ad2753d7 100644 --- a/testing/test_service.cc +++ b/testing/test_service.cc @@ -11,7 +11,7 @@ #include "authentication.hh" #include "param_node.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" #include #include diff --git a/testing/test_specifier.cc b/testing/test_specifier.cc index f68102bf..bc4f6b28 100644 --- a/testing/test_specifier.cc +++ b/testing/test_specifier.cc @@ -7,7 +7,7 @@ #include "specifier.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" TEST_CASE( "specifier", "[message]" ) { diff --git a/testing/test_throw_reply.cc b/testing/test_throw_reply.cc index 3de8f65b..aa893d15 100644 --- a/testing/test_throw_reply.cc +++ b/testing/test_throw_reply.cc @@ -9,7 +9,7 @@ #include "logger.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" LOGGER( testlog, "test_throw_reply" ); diff --git a/testing/test_uuid.cc b/testing/test_uuid.cc index 4d15b8e0..02394aa1 100644 --- a/testing/test_uuid.cc +++ b/testing/test_uuid.cc @@ -7,7 +7,8 @@ #include "uuid.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" +#include "catch2/matchers/catch_matchers_all.hpp" TEST_CASE( "uuid", "[message]" ) { @@ -19,25 +20,25 @@ TEST_CASE( "uuid", "[message]" ) std::string t_test_string_1( "AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE" ); dripline::uuid_t t_test_uuid_1; REQUIRE_NOTHROW( t_test_uuid_1 = dripline::uuid_from_string( t_test_string_1 ) ); - REQUIRE_THAT( t_test_string_1, Catch::Equals(dripline::string_from_uuid(t_test_uuid_1), Catch::CaseSensitive::No) ); + REQUIRE_THAT( t_test_string_1, Catch::Matchers::Equals(dripline::string_from_uuid(t_test_uuid_1), Catch::CaseSensitive::No) ); std::string t_test_string_2( "{AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE}" ); dripline::uuid_t t_test_uuid_2; REQUIRE_NOTHROW( t_test_uuid_2 = dripline::uuid_from_string( t_test_string_2 ) ); // compare to t_test_string_1 because the to_string conversion adds dashes and has no braces - REQUIRE_THAT( t_test_string_1, Catch::Equals(dripline::string_from_uuid(t_test_uuid_2), Catch::CaseSensitive::No) ); + REQUIRE_THAT( t_test_string_1, Catch::Matchers::Equals(dripline::string_from_uuid(t_test_uuid_2), Catch::CaseSensitive::No) ); std::string t_test_string_3( "AAAAAAAABBBBCCCCDDDDEEEEEEEEEEEE" ); dripline::uuid_t t_test_uuid_3; REQUIRE_NOTHROW( t_test_uuid_3 = dripline::uuid_from_string( t_test_string_3 ) ); // compare to t_test_string_1 because the to_string conversion adds dashes and has no braces - REQUIRE_THAT( t_test_string_1, Catch::Equals(dripline::string_from_uuid(t_test_uuid_3), Catch::CaseSensitive::No) ); + REQUIRE_THAT( t_test_string_1, Catch::Matchers::Equals(dripline::string_from_uuid(t_test_uuid_3), Catch::CaseSensitive::No) ); std::string t_test_string_4( "{AAAAAAAABBBBCCCCDDDDEEEEEEEEEEEE}" ); dripline::uuid_t t_test_uuid_4; REQUIRE_NOTHROW( t_test_uuid_4 = dripline::uuid_from_string( t_test_string_4 ) ); // compare to t_test_string_1 because the to_string conversion adds dashes and has no braces - REQUIRE_THAT( t_test_string_1, Catch::Equals(dripline::string_from_uuid(t_test_uuid_4), Catch::CaseSensitive::No) ); + REQUIRE_THAT( t_test_string_1, Catch::Matchers::Equals(dripline::string_from_uuid(t_test_uuid_4), Catch::CaseSensitive::No) ); } diff --git a/testing/test_version_store.cc b/testing/test_version_store.cc index af7b4162..bafe67dc 100644 --- a/testing/test_version_store.cc +++ b/testing/test_version_store.cc @@ -9,7 +9,7 @@ #include "dripline_version.hh" -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp" namespace dripline diff --git a/testing/use_catch.cc b/testing/use_catch.cc index 4cb169c2..f76be9eb 100644 --- a/testing/use_catch.cc +++ b/testing/use_catch.cc @@ -7,4 +7,4 @@ // Tells Catch to provide a main() #define CATCH_CONFIG_MAIN -#include "catch.hpp" +#include "catch2/catch_test_macros.hpp"