CTest: Write JUnit testsuite timestamp in UTC

The `<testsuite timestamp>` attribute of the `--output-junit` report was
written in local time with no time zone designator, so downstream tools
parsing the JUnit XML could not determine the actual instant without
knowing the producing machine's time zone.  Two reports produced in
different time zones could not be compared.

Write the timestamp in UTC with a trailing `Z` (ISO 8601 / xs:dateTime),
making it an unambiguous instant.
This commit is contained in:
Uday authored and Brad King committed 2026-11-02 10:53:39 -05:00
1 parent 8e91f7aa9b
commit e026c11ed2
3 files changed
+7 -1

No files matched your search

+1 -1
View File
@@ -2777,7 +2777,7 @@ bool cmCTestTestHandler::WriteJUnitXML()
cmTimestamp cmts;
xml.Attribute("timestamp",
cmts.CreateTimestampFromTimeT(start_test_time_t,
"%Y-%m-%dT%H:%M:%S", false));
"%Y-%m-%dT%H:%M:%SZ", true));
// Write <testcase> elements.
for (cmCTestTestResult const& result : resultsSet) {
@@ -4,6 +4,9 @@ if(junit_xml_file)
if(NOT "${junit_xml}" MATCHES "tests=\"5\"")
set(RunCMake_TEST_FAILED "tests=\"5\" not found when expected")
endif()
if(NOT "${junit_xml}" MATCHES "timestamp=\"[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z\"")
set(RunCMake_TEST_FAILED "UTC timestamp=\"...Z\" not found when expected")
endif()
if(NOT "${junit_xml}" MATCHES "failures=\"1\"")
set(RunCMake_TEST_FAILED "failures=\"1\" not found when expected")
endif()
@@ -4,6 +4,9 @@ if(junit_xml_file)
if(NOT "${junit_xml}" MATCHES "tests=\"1\"")
set(RunCMake_TEST_FAILED "tests=\"1\" not found when expected")
endif()
if(NOT "${junit_xml}" MATCHES "timestamp=\"[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z\"")
set(RunCMake_TEST_FAILED "UTC timestamp=\"...Z\" not found when expected")
endif()
if(NOT "${junit_xml}" MATCHES "failures=\"0\"")
set(RunCMake_TEST_FAILED "failures=\"0\" not found when expected")
endif()