From d77132d623bb78ed77a082ba15d28d465450c6f8 Mon Sep 17 00:00:00 2001 From: Marco Clemencic <marco.clemencic@cern.ch> Date: Mon, 12 Dec 2022 10:19:40 +0100 Subject: [PATCH] Make Catch2 based test compatible with Catch2 v3 --- .../tests/src/CounterSerializationTest.cpp | 19 +++++++++++++++---- .../tests/src/MonitoringEntityUnitTest.cpp | 9 ++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/GaudiKernel/tests/src/CounterSerializationTest.cpp b/GaudiKernel/tests/src/CounterSerializationTest.cpp index 490133c1be..39dbed5035 100644 --- a/GaudiKernel/tests/src/CounterSerializationTest.cpp +++ b/GaudiKernel/tests/src/CounterSerializationTest.cpp @@ -9,7 +9,18 @@ * or submit itself to any jurisdiction. * \***********************************************************************************/ #include <Gaudi/Accumulators.h> -#include <catch2/catch.hpp> +#if __has_include( <catch2/catch.hpp>) +// Catch2 v2 +# include <catch2/catch.hpp> +namespace Catch { + using Detail::Approx; +} +#else +// Catch2 v3 +# include <catch2/catch_approx.hpp> +# include <catch2/catch_template_test_macros.hpp> +# include <catch2/catch_test_macros.hpp> +#endif using namespace Gaudi::Accumulators; @@ -109,7 +120,7 @@ namespace { CHECK( j["sum"].get<double>() == 60 ); CHECK( j["mean"].get<double>() == 20 ); CHECK( j["sum2"].get<double>() == 1400 ); - CHECK( j["standard_deviation"].get<double>() == Approx( 8.164966 ) ); + CHECK( j["standard_deviation"].get<double>() == Catch::Approx( 8.164966 ) ); } } }; @@ -134,7 +145,7 @@ namespace { CHECK( j["sum"].get<double>() == 60 ); CHECK( j["mean"].get<double>() == 20 ); CHECK( j["sum2"].get<double>() == 1400 ); - CHECK( j["standard_deviation"].get<double>() == Approx( 8.164966 ) ); + CHECK( j["standard_deviation"].get<double>() == Catch::Approx( 8.164966 ) ); CHECK( j["min"].get<double>() == 10 ); CHECK( j["max"].get<double>() == 30 ); } @@ -160,7 +171,7 @@ namespace { CHECK( j["nTrueEntries"].get<double>() == 5 ); CHECK( j["nFalseEntries"].get<double>() == 5 ); CHECK( j["efficiency"].get<double>() == 0.5 ); - CHECK( j["efficiencyErr"].get<double>() == Approx( 0.158114 ) ); + CHECK( j["efficiencyErr"].get<double>() == Catch::Approx( 0.158114 ) ); } } }; diff --git a/GaudiKernel/tests/src/MonitoringEntityUnitTest.cpp b/GaudiKernel/tests/src/MonitoringEntityUnitTest.cpp index 375449fe5c..76321e2f3a 100644 --- a/GaudiKernel/tests/src/MonitoringEntityUnitTest.cpp +++ b/GaudiKernel/tests/src/MonitoringEntityUnitTest.cpp @@ -9,12 +9,19 @@ * or submit itself to any jurisdiction. * \***********************************************************************************/ #include <Gaudi/Accumulators.h> -#include <catch2/catch.hpp> #include <map> #include <optional> #include <string> #include <utility> +#if __has_include( <catch2/catch.hpp>) +// Catch2 v2 +# include <catch2/catch.hpp> +#else +// Catch2 v3 +# include <catch2/catch_test_macros.hpp> +#endif + namespace { /// Mock helpers to be able to invoke counters auto registering constructor. Gaudi::Monitoring::Hub localHub; -- GitLab