Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Cleanup reporting of rng seed in existing reporters

Commit
1d9696d22d4a33b106dee1e3f69cb310d855b637
Author
Martin Hořeňovský ·
Parents
ed1f343a41ef

Files · Download .tar.gz

Changes

 src/catch2/reporters/catch_reporter_console.cpp |  3 +--
 src/catch2/reporters/catch_reporter_junit.cpp   | 12 +++++-------
 src/catch2/reporters/catch_reporter_xml.cpp     |  9 +++------
 tests/SelfTest/Baselines/junit.sw.approved.txt  |  2 +-
 tests/SelfTest/Baselines/xml.sw.approved.txt    |  3 +--
 5 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp
index d7c2dd59..5c8b6ec7 100644
--- a/src/catch2/reporters/catch_reporter_console.cpp
+++ b/src/catch2/reporters/catch_reporter_console.cpp
@@ -520,8 +520,7 @@ void ConsoleReporter::lazyPrintRunInfo() {
         << " is a Catch v" << libraryVersion() << " host application.\n"
         << "Run with -? for options\n\n";
 
-    if (m_config->rngSeed() != 0)
-        stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n";
+    stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n";
 
     currentTestRunInfo.used = true;
 }
diff --git a/src/catch2/reporters/catch_reporter_junit.cpp b/src/catch2/reporters/catch_reporter_junit.cpp
index b923aee6..8e8da3ca 100644
--- a/src/catch2/reporters/catch_reporter_junit.cpp
+++ b/src/catch2/reporters/catch_reporter_junit.cpp
@@ -114,19 +114,17 @@ namespace Catch {
             xml.writeAttribute( "time"_sr, suiteTime );
         xml.writeAttribute( "timestamp"_sr, getCurrentTimestamp() );
 
-        // Write properties if there are any
-        if (m_config->hasTestFilters() || m_config->rngSeed() != 0) {
+        // Write properties
+        {
             auto properties = xml.scopedElement("properties");
+            xml.scopedElement("property")
+                .writeAttribute("name"_sr, "random-seed"_sr)
+                .writeAttribute("value"_sr, m_config->rngSeed());
             if (m_config->hasTestFilters()) {
                 xml.scopedElement("property")
                     .writeAttribute("name"_sr, "filters"_sr)
                     .writeAttribute("value"_sr, serializeFilters(m_config->getTestsOrTags()));
             }
-            if (m_config->rngSeed() != 0) {
-                xml.scopedElement("property")
-                    .writeAttribute("name"_sr, "random-seed"_sr)
-                    .writeAttribute("value"_sr, m_config->rngSeed());
-            }
         }
 
         // Write test cases
diff --git a/src/catch2/reporters/catch_reporter_xml.cpp b/src/catch2/reporters/catch_reporter_xml.cpp
index 4e2a9a34..8c3338cb 100644
--- a/src/catch2/reporters/catch_reporter_xml.cpp
+++ b/src/catch2/reporters/catch_reporter_xml.cpp
@@ -51,14 +51,11 @@ namespace Catch {
         std::string stylesheetRef = getStylesheetRef();
         if( !stylesheetRef.empty() )
             m_xml.writeStylesheetRef( stylesheetRef );
-        m_xml.startElement( "Catch2TestRun" );
-        if( !m_config->name().empty() )
-            m_xml.writeAttribute( "name"_sr, m_config->name() );
+        m_xml.startElement("Catch2TestRun")
+             .writeAttribute("name"_sr, m_config->name())
+             .writeAttribute("rng-seed"_sr, m_config->rngSeed());
         if (m_config->testSpec().hasFilters())
             m_xml.writeAttribute( "filters"_sr, serializeFilters( m_config->getTestsOrTags() ) );
-        if( m_config->rngSeed() != 0 )
-            m_xml.scopedElement( "Randomness" )
-                .writeAttribute( "seed"_sr, m_config->rngSeed() );
     }
 
     void XmlReporter::testCaseStarting( TestCaseInfo const& testInfo ) {
diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt
index 26afed94..d99f25e8 100644
--- a/tests/SelfTest/Baselines/junit.sw.approved.txt
+++ b/tests/SelfTest/Baselines/junit.sw.approved.txt
@@ -3,8 +3,8 @@
 >
   <testsuite name="<exe-name>" errors="17" failures="129" tests="2127" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <properties>
-      <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
       <property name="random-seed" value="1"/>
+      <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
     </properties>
     <testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}" status="run"/>
     <testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}" status="run"/>
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index 13544d49..2fee44e4 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<Catch2TestRun name="<exe-name>" filters="~[!nonportable]~[!benchmark]~[approvals] *">
-  <Randomness seed="1"/>
+<Catch2TestRun name="<exe-name>" rng-seed="1" filters="~[!nonportable]~[!benchmark]~[approvals] *">
   <TestCase name="# A test name that starts with a #" filename="tests/<exe-name>/UsageTests/Misc.tests.cpp" >
     <OverallResult success="true"/>
   </TestCase>