From fa306fc85eca7cc68a5362c503019fa823cbe411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Wed, 14 Aug 2024 12:32:44 +0200 Subject: [PATCH] Improve performance of SonarQube reporter handling passing assertions This mirrors the changes done to the JUnit reporter in commit fe483c056d9516d3550519c29fbf14a4d84d06d4 --- .../reporters/catch_reporter_sonarqube.cpp | 4 +- .../reporters/catch_reporter_sonarqube.hpp | 2 +- .../Baselines/sonarqube.sw.approved.txt | 154 ++++++++++++++++++ .../Baselines/sonarqube.sw.multi.approved.txt | 154 ++++++++++++++++++ 4 files changed, 311 insertions(+), 3 deletions(-) diff --git a/src/catch2/reporters/catch_reporter_sonarqube.cpp b/src/catch2/reporters/catch_reporter_sonarqube.cpp index 9c391b1f..2c3eb1cd 100644 --- a/src/catch2/reporters/catch_reporter_sonarqube.cpp +++ b/src/catch2/reporters/catch_reporter_sonarqube.cpp @@ -73,9 +73,9 @@ namespace Catch { if (!rootName.empty()) name = rootName + '/' + name; - if ( sectionNode.hasAnyAssertions() + if ( sectionNode.stats.assertions.total() > 0 || !sectionNode.stdOut.empty() - || !sectionNode.stdErr.empty() ) { + || !sectionNode.stdErr.empty() ) { XmlWriter::ScopedElement e = xml.scopedElement("testCase"); xml.writeAttribute("name"_sr, name); xml.writeAttribute("duration"_sr, static_cast(sectionNode.stats.durationInSeconds * 1000)); diff --git a/src/catch2/reporters/catch_reporter_sonarqube.hpp b/src/catch2/reporters/catch_reporter_sonarqube.hpp index 906578bb..509f411e 100644 --- a/src/catch2/reporters/catch_reporter_sonarqube.hpp +++ b/src/catch2/reporters/catch_reporter_sonarqube.hpp @@ -21,7 +21,7 @@ namespace Catch { : CumulativeReporterBase(CATCH_MOVE(config)) , xml(m_stream) { m_preferences.shouldRedirectStdOut = true; - m_preferences.shouldReportAllAssertions = true; + m_preferences.shouldReportAllAssertions = false; m_shouldStoreSuccesfulAssertions = false; } diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 1b5b8757..1cd2858b 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -14,51 +14,66 @@ at AssertionHandler.tests.cpp: + + + + + + + + + + + + + + + @@ -67,13 +82,16 @@ at AssertionHandler.tests.cpp: + + + @@ -82,35 +100,49 @@ at AssertionHandler.tests.cpp: + + + + + + + + + + + + + + @@ -130,6 +162,7 @@ at AssertionHandler.tests.cpp: + @@ -139,6 +172,7 @@ at AssertionHandler.tests.cpp: + @@ -150,10 +184,12 @@ at AssertionHandler.tests.cpp: + + @@ -176,6 +212,7 @@ at AssertionHandler.tests.cpp: + @@ -217,6 +254,7 @@ at AssertionHandler.tests.cpp: + @@ -230,11 +268,13 @@ at AssertionHandler.tests.cpp: + + @@ -243,24 +283,29 @@ at AssertionHandler.tests.cpp: + + + + + @@ -268,6 +313,7 @@ at AssertionHandler.tests.cpp: + @@ -279,6 +325,7 @@ at AssertionHandler.tests.cpp: + @@ -286,6 +333,7 @@ at AssertionHandler.tests.cpp: + @@ -299,16 +347,20 @@ at AssertionHandler.tests.cpp: + + + + @@ -319,6 +371,7 @@ at AssertionHandler.tests.cpp: + @@ -348,14 +401,27 @@ at AssertionHandler.tests.cpp: + + + + + + + + + + + + + @@ -529,6 +595,7 @@ with expansion: at Class.tests.cpp: + @@ -540,6 +607,7 @@ at Class.tests.cpp: + @@ -749,24 +817,28 @@ at Condition.tests.cpp: + FAILED: at Condition.tests.cpp: + FAILED: at Condition.tests.cpp: + FAILED: at Condition.tests.cpp: + FAILED: @@ -933,6 +1005,7 @@ at Decomposition.tests.cpp: + FAILED: @@ -982,6 +1055,7 @@ custom std exception at Exception.tests.cpp: + @@ -1073,6 +1147,7 @@ unexpected exception at Exception.tests.cpp: + FAILED: @@ -1092,21 +1167,27 @@ at Generators.tests.cpp: + + + + + + @@ -1116,6 +1197,7 @@ at Generators.tests.cpp: + @@ -1125,8 +1207,10 @@ at Generators.tests.cpp: + + @@ -1223,6 +1307,7 @@ at Matchers.tests.cpp: + @@ -1230,6 +1315,7 @@ at Matchers.tests.cpp: + @@ -1302,10 +1388,13 @@ at Matchers.tests.cpp: + + + FAILED: @@ -1324,11 +1413,13 @@ with expansion: at Matchers.tests.cpp: + + FAILED: @@ -1423,82 +1514,114 @@ at Matchers.tests.cpp: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1597,6 +1720,8 @@ at Message.tests.cpp: + + @@ -1613,6 +1738,8 @@ previous unscoped info SHOULD not be seen at Message.tests.cpp: + + @@ -1685,6 +1812,7 @@ with expansion: at Misc.tests.cpp: + @@ -1705,7 +1833,9 @@ to infinity and beyond at Misc.tests.cpp: + + @@ -1834,10 +1964,14 @@ with expansion: at Misc.tests.cpp: + + + + FAILED: @@ -1914,6 +2048,8 @@ Testing if fib[7] (21) is even at Misc.tests.cpp: + + FAILED: @@ -1923,14 +2059,18 @@ with expansion: at Misc.tests.cpp: + + + + FAILED: @@ -1949,6 +2089,7 @@ at Misc.tests.cpp: + @@ -2019,6 +2160,9 @@ FAILED: at Skip.tests.cpp: + + + SKIPPED @@ -2026,6 +2170,7 @@ at Skip.tests.cpp: + @@ -2054,20 +2199,26 @@ at Skip.tests.cpp: + + + + + + @@ -2112,6 +2263,7 @@ FAILED: at Tricky.tests.cpp: + @@ -2147,6 +2299,7 @@ at Tricky.tests.cpp: + @@ -2155,6 +2308,7 @@ at Tricky.tests.cpp: + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index dc6b3b31..02f4bc89 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -13,51 +13,66 @@ at AssertionHandler.tests.cpp: + + + + + + + + + + + + + + + @@ -66,13 +81,16 @@ at AssertionHandler.tests.cpp: + + + @@ -81,35 +99,49 @@ at AssertionHandler.tests.cpp: + + + + + + + + + + + + + + @@ -129,6 +161,7 @@ at AssertionHandler.tests.cpp: + @@ -138,6 +171,7 @@ at AssertionHandler.tests.cpp: + @@ -149,10 +183,12 @@ at AssertionHandler.tests.cpp: + + @@ -175,6 +211,7 @@ at AssertionHandler.tests.cpp: + @@ -216,6 +253,7 @@ at AssertionHandler.tests.cpp: + @@ -229,11 +267,13 @@ at AssertionHandler.tests.cpp: + + @@ -242,24 +282,29 @@ at AssertionHandler.tests.cpp: + + + + + @@ -267,6 +312,7 @@ at AssertionHandler.tests.cpp: + @@ -278,6 +324,7 @@ at AssertionHandler.tests.cpp: + @@ -285,6 +332,7 @@ at AssertionHandler.tests.cpp: + @@ -298,16 +346,20 @@ at AssertionHandler.tests.cpp: + + + + @@ -318,6 +370,7 @@ at AssertionHandler.tests.cpp: + @@ -347,14 +400,27 @@ at AssertionHandler.tests.cpp: + + + + + + + + + + + + + @@ -528,6 +594,7 @@ with expansion: at Class.tests.cpp: + @@ -539,6 +606,7 @@ at Class.tests.cpp: + @@ -748,24 +816,28 @@ at Condition.tests.cpp: + FAILED: at Condition.tests.cpp: + FAILED: at Condition.tests.cpp: + FAILED: at Condition.tests.cpp: + FAILED: @@ -932,6 +1004,7 @@ at Decomposition.tests.cpp: + FAILED: @@ -981,6 +1054,7 @@ custom std exception at Exception.tests.cpp: + @@ -1072,6 +1146,7 @@ unexpected exception at Exception.tests.cpp: + FAILED: @@ -1091,21 +1166,27 @@ at Generators.tests.cpp: + + + + + + @@ -1115,6 +1196,7 @@ at Generators.tests.cpp: + @@ -1124,8 +1206,10 @@ at Generators.tests.cpp: + + @@ -1222,6 +1306,7 @@ at Matchers.tests.cpp: + @@ -1229,6 +1314,7 @@ at Matchers.tests.cpp: + @@ -1301,10 +1387,13 @@ at Matchers.tests.cpp: + + + FAILED: @@ -1323,11 +1412,13 @@ with expansion: at Matchers.tests.cpp: + + FAILED: @@ -1422,82 +1513,114 @@ at Matchers.tests.cpp: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1596,6 +1719,8 @@ at Message.tests.cpp: + + @@ -1612,6 +1737,8 @@ previous unscoped info SHOULD not be seen at Message.tests.cpp: + + @@ -1684,6 +1811,7 @@ with expansion: at Misc.tests.cpp: + @@ -1704,7 +1832,9 @@ to infinity and beyond at Misc.tests.cpp: + + @@ -1833,10 +1963,14 @@ with expansion: at Misc.tests.cpp: + + + + FAILED: @@ -1913,6 +2047,8 @@ Testing if fib[7] (21) is even at Misc.tests.cpp: + + FAILED: @@ -1922,14 +2058,18 @@ with expansion: at Misc.tests.cpp: + + + + FAILED: @@ -1948,6 +2088,7 @@ at Misc.tests.cpp: + @@ -2018,6 +2159,9 @@ FAILED: at Skip.tests.cpp: + + + SKIPPED @@ -2025,6 +2169,7 @@ at Skip.tests.cpp: + @@ -2053,20 +2198,26 @@ at Skip.tests.cpp: + + + + + + @@ -2111,6 +2262,7 @@ FAILED: at Tricky.tests.cpp: + @@ -2146,6 +2298,7 @@ at Tricky.tests.cpp: + @@ -2154,6 +2307,7 @@ at Tricky.tests.cpp: +