From a1a28a83a7a1c1e64077aecfa4309fae2bc6a05c Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Thu, 17 Jun 2021 11:49:21 +0000 Subject: [PATCH 1/3] Add section logging to test loggers --- tests/dist/main.cpp | 14 +++++++++++++- tests/test/main.cpp | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/dist/main.cpp b/tests/dist/main.cpp index 2810b4756..bbf1c6780 100644 --- a/tests/dist/main.cpp +++ b/tests/dist/main.cpp @@ -15,13 +15,25 @@ using namespace faabric::scheduler; struct LogListener : Catch::TestEventListenerBase { + // Note, we must call base class versions of overridden methods + // https://github.com/catchorg/Catch2/pull/1617 using TestEventListenerBase::TestEventListenerBase; void testCaseStarting(Catch::TestCaseInfo const& testInfo) override { + this->Catch::TestEventListenerBase::testCaseStarting(testInfo); - SPDLOG_INFO("---------------------------------------------"); + SPDLOG_INFO("============================================="); SPDLOG_INFO("TEST: {}", testInfo.name); + SPDLOG_INFO("============================================="); + } + + void sectionStarting(Catch::SectionInfo const& sectionInfo) override + { + this->Catch::TestEventListenerBase::sectionStarting(sectionInfo); + + SPDLOG_INFO("---------------------------------------------"); + SPDLOG_INFO("SECTION: {}", sectionInfo.name); SPDLOG_INFO("---------------------------------------------"); } }; diff --git a/tests/test/main.cpp b/tests/test/main.cpp index 11d633ca8..c492eefb2 100644 --- a/tests/test/main.cpp +++ b/tests/test/main.cpp @@ -9,13 +9,25 @@ struct LogListener : Catch::TestEventListenerBase { + // Note, we must call base class versions of overridden methods + // https://github.com/catchorg/Catch2/pull/1617 using TestEventListenerBase::TestEventListenerBase; void testCaseStarting(Catch::TestCaseInfo const& testInfo) override { + this->Catch::TestEventListenerBase::testCaseStarting(testInfo); - SPDLOG_INFO("---------------------------------------------"); + SPDLOG_INFO("============================================="); SPDLOG_INFO("TEST: {}", testInfo.name); + SPDLOG_INFO("============================================="); + } + + void sectionStarting(Catch::SectionInfo const& sectionInfo) override + { + this->Catch::TestEventListenerBase::sectionStarting(sectionInfo); + + SPDLOG_INFO("---------------------------------------------"); + SPDLOG_INFO("SECTION: {}", sectionInfo.name); SPDLOG_INFO("---------------------------------------------"); } }; From 5391c05bdf428d292402b5a58a068ec8486afa4e Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Thu, 17 Jun 2021 13:21:30 +0000 Subject: [PATCH 2/3] Avoid duplicate section logging --- tests/dist/main.cpp | 10 +++++++--- tests/test/main.cpp | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/dist/main.cpp b/tests/dist/main.cpp index bbf1c6780..ccfb59ca1 100644 --- a/tests/dist/main.cpp +++ b/tests/dist/main.cpp @@ -32,9 +32,13 @@ struct LogListener : Catch::TestEventListenerBase { this->Catch::TestEventListenerBase::sectionStarting(sectionInfo); - SPDLOG_INFO("---------------------------------------------"); - SPDLOG_INFO("SECTION: {}", sectionInfo.name); - SPDLOG_INFO("---------------------------------------------"); + // Tests without any sections will be default have one section with the + // same name as the test + if (sectionInfo.name != currentTestCaseInfo->name) { + SPDLOG_INFO("---------------------------------------------"); + SPDLOG_INFO("SECTION: {}", sectionInfo.name); + SPDLOG_INFO("---------------------------------------------"); + } } }; diff --git a/tests/test/main.cpp b/tests/test/main.cpp index c492eefb2..67c260647 100644 --- a/tests/test/main.cpp +++ b/tests/test/main.cpp @@ -26,9 +26,13 @@ struct LogListener : Catch::TestEventListenerBase { this->Catch::TestEventListenerBase::sectionStarting(sectionInfo); - SPDLOG_INFO("---------------------------------------------"); - SPDLOG_INFO("SECTION: {}", sectionInfo.name); - SPDLOG_INFO("---------------------------------------------"); + // Tests without any sections will be default have one section with the + // same name as the test + if (sectionInfo.name != currentTestCaseInfo->name) { + SPDLOG_INFO("---------------------------------------------"); + SPDLOG_INFO("SECTION: {}", sectionInfo.name); + SPDLOG_INFO("---------------------------------------------"); + } } }; From 26aa1f9b7a8cc03c5b1bfa9c851f5018743b67a0 Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Thu, 17 Jun 2021 13:26:39 +0000 Subject: [PATCH 3/3] Macro-ise --- tests/dist/main.cpp | 31 +------------------------------ tests/test/main.cpp | 31 +------------------------------ tests/utils/faabric_utils.h | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 60 deletions(-) diff --git a/tests/dist/main.cpp b/tests/dist/main.cpp index ccfb59ca1..424110470 100644 --- a/tests/dist/main.cpp +++ b/tests/dist/main.cpp @@ -13,36 +13,7 @@ using namespace faabric::scheduler; -struct LogListener : Catch::TestEventListenerBase -{ - // Note, we must call base class versions of overridden methods - // https://github.com/catchorg/Catch2/pull/1617 - using TestEventListenerBase::TestEventListenerBase; - - void testCaseStarting(Catch::TestCaseInfo const& testInfo) override - { - this->Catch::TestEventListenerBase::testCaseStarting(testInfo); - - SPDLOG_INFO("============================================="); - SPDLOG_INFO("TEST: {}", testInfo.name); - SPDLOG_INFO("============================================="); - } - - void sectionStarting(Catch::SectionInfo const& sectionInfo) override - { - this->Catch::TestEventListenerBase::sectionStarting(sectionInfo); - - // Tests without any sections will be default have one section with the - // same name as the test - if (sectionInfo.name != currentTestCaseInfo->name) { - SPDLOG_INFO("---------------------------------------------"); - SPDLOG_INFO("SECTION: {}", sectionInfo.name); - SPDLOG_INFO("---------------------------------------------"); - } - } -}; - -CATCH_REGISTER_LISTENER(LogListener) +FAABRIC_CATCH_LOGGER int main(int argc, char* argv[]) { diff --git a/tests/test/main.cpp b/tests/test/main.cpp index 67c260647..bddede144 100644 --- a/tests/test/main.cpp +++ b/tests/test/main.cpp @@ -7,36 +7,7 @@ #include #include -struct LogListener : Catch::TestEventListenerBase -{ - // Note, we must call base class versions of overridden methods - // https://github.com/catchorg/Catch2/pull/1617 - using TestEventListenerBase::TestEventListenerBase; - - void testCaseStarting(Catch::TestCaseInfo const& testInfo) override - { - this->Catch::TestEventListenerBase::testCaseStarting(testInfo); - - SPDLOG_INFO("============================================="); - SPDLOG_INFO("TEST: {}", testInfo.name); - SPDLOG_INFO("============================================="); - } - - void sectionStarting(Catch::SectionInfo const& sectionInfo) override - { - this->Catch::TestEventListenerBase::sectionStarting(sectionInfo); - - // Tests without any sections will be default have one section with the - // same name as the test - if (sectionInfo.name != currentTestCaseInfo->name) { - SPDLOG_INFO("---------------------------------------------"); - SPDLOG_INFO("SECTION: {}", sectionInfo.name); - SPDLOG_INFO("---------------------------------------------"); - } - } -}; - -CATCH_REGISTER_LISTENER(LogListener) +FAABRIC_CATCH_LOGGER int main(int argc, char* argv[]) { diff --git a/tests/utils/faabric_utils.h b/tests/utils/faabric_utils.h index acdcbad8a..24f078d60 100644 --- a/tests/utils/faabric_utils.h +++ b/tests/utils/faabric_utils.h @@ -12,6 +12,30 @@ using namespace faabric; #define SHORT_TEST_TIMEOUT_MS 1000 +#define FAABRIC_CATCH_LOGGER \ + struct LogListener : Catch::TestEventListenerBase \ + { \ + using TestEventListenerBase::TestEventListenerBase; \ + void testCaseStarting(Catch::TestCaseInfo const& testInfo) override \ + { \ + this->Catch::TestEventListenerBase::testCaseStarting(testInfo); \ + SPDLOG_INFO("============================================="); \ + SPDLOG_INFO("TEST: {}", testInfo.name); \ + SPDLOG_INFO("============================================="); \ + } \ + \ + void sectionStarting(Catch::SectionInfo const& sectionInfo) override \ + { \ + this->Catch::TestEventListenerBase::sectionStarting(sectionInfo); \ + if (sectionInfo.name != currentTestCaseInfo->name) { \ + SPDLOG_INFO("---------------------------------------------"); \ + SPDLOG_INFO("SECTION: {}", sectionInfo.name); \ + SPDLOG_INFO("---------------------------------------------"); \ + } \ + } \ + }; \ + CATCH_REGISTER_LISTENER(LogListener) + namespace tests { void cleanFaabric();