Skip to content

Commit

Permalink
Upgraded catch2 to v3 and take advantage of creating our own main to …
Browse files Browse the repository at this point in the history
…include STOP_LOGGING
  • Loading branch information
nsoblath committed Oct 10, 2024
1 parent 96f2165 commit 0798044
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 29 deletions.
32 changes: 23 additions & 9 deletions testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +42,6 @@ set( testing_SOURCES

set( testing_LIBS
Dripline
Catch
)

if( Dripline_BUILD_EXAMPLES )
Expand All @@ -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}
Expand Down
20 changes: 20 additions & 0 deletions testing/run_dl_tests.cc
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 2 additions & 1 deletion testing/test_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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" );

Expand Down
2 changes: 1 addition & 1 deletion testing/test_amqp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "amqp.hh"

#include "catch.hpp"
#include "catch2/catch_test_macros.hpp"

TEST_CASE( "amqp_table", "[amqp]" )
{
Expand Down
2 changes: 1 addition & 1 deletion testing/test_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "authentication.hh"
#include "param_codec.hh"

#include "catch.hpp"
#include "catch2/catch_test_macros.hpp"

#include <boost/filesystem.hpp>

Expand Down
2 changes: 1 addition & 1 deletion testing/test_dripline_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "logger.hh"

#include "catch.hpp"
#include "catch2/catch_test_macros.hpp"

LOGGER( testlog, "test_dripline_error" );

Expand Down
2 changes: 1 addition & 1 deletion testing/test_endpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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]" )
{
Expand Down
3 changes: 2 additions & 1 deletion testing/test_examples_oscillator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

#include "oscillator.hh"

#include "catch.hpp"
#include "catch2/catch_test_macros.hpp"
#include "catch2/matchers/catch_matchers_all.hpp"

#include <cmath>

Expand Down
2 changes: 1 addition & 1 deletion testing/test_lockout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testing/test_messages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "logger.hh"

#include "catch.hpp"
#include "catch2/catch_test_macros.hpp"

LOGGER( testlog, "test_message" );

Expand Down
2 changes: 1 addition & 1 deletion testing/test_return_codes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "logger.hh"

#include "catch.hpp"
#include "catch2/catch_test_macros.hpp"

#include <algorithm>
#include <sstream>
Expand Down
2 changes: 1 addition & 1 deletion testing/test_scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "logger.hh"

#include "catch.hpp"
#include "catch2/catch_test_macros.hpp"

#include <thread>

Expand Down
2 changes: 1 addition & 1 deletion testing/test_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "authentication.hh"
#include "param_node.hh"

#include "catch.hpp"
#include "catch2/catch_test_macros.hpp"

#include <chrono>
#include <future>
Expand Down
2 changes: 1 addition & 1 deletion testing/test_specifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "specifier.hh"

#include "catch.hpp"
#include "catch2/catch_test_macros.hpp"

TEST_CASE( "specifier", "[message]" )
{
Expand Down
2 changes: 1 addition & 1 deletion testing/test_throw_reply.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "logger.hh"

#include "catch.hpp"
#include "catch2/catch_test_macros.hpp"

LOGGER( testlog, "test_throw_reply" );

Expand Down
11 changes: 6 additions & 5 deletions testing/test_uuid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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]" )
{
Expand All @@ -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) );
}


Expand Down
2 changes: 1 addition & 1 deletion testing/test_version_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "dripline_version.hh"

#include "catch.hpp"
#include "catch2/catch_test_macros.hpp"


namespace dripline
Expand Down
2 changes: 1 addition & 1 deletion testing/use_catch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

// Tells Catch to provide a main()
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "catch2/catch_test_macros.hpp"

0 comments on commit 0798044

Please sign in to comment.