diff options
author | Abseil Team <absl-team@google.com> | 2023-02-02 15:14:30 (GMT) |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-02-02 15:15:23 (GMT) |
commit | 6f21175f57afa370a707026fcaf246eb081d1639 (patch) | |
tree | f527314d4fde58f4113c0bfc5dbebaf73186ab8e /googletest/src | |
parent | ebedaa18c7cafa15f06ab3d814440e510fad9559 (diff) | |
download | googletest-6f21175f57afa370a707026fcaf246eb081d1639.zip googletest-6f21175f57afa370a707026fcaf246eb081d1639.tar.gz googletest-6f21175f57afa370a707026fcaf246eb081d1639.tar.bz2 |
Add a trailing decimal point to FormatTimeInMillisAsSeconds() output when input
is an exact N seconds.
PiperOrigin-RevId: 506610898
Change-Id: Idcd705c719e0e721148c350c8a14f27b9eb5c4f7
Diffstat (limited to 'googletest/src')
-rw-r--r-- | googletest/src/gtest-internal-inl.h | 3 | ||||
-rw-r--r-- | googletest/src/gtest.cc | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index 2c9db4f..9fbcfd3 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -92,7 +92,8 @@ GTEST_API_ TimeInMillis GetTimeInMillis(); // Returns true if and only if Google Test should use colors in the output. GTEST_API_ bool ShouldUseColor(bool stdout_is_tty); -// Formats the given time in milliseconds as seconds. +// Formats the given time in milliseconds as seconds. If the input is an exact N +// seconds, the output has a trailing decimal point (e.g., "N." intead of "N"). GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms); // Converts the given time in milliseconds to a date string in the ISO 8601 diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 19acb1c..b928943 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -46,6 +46,7 @@ #include <cstdint> #include <initializer_list> #include <iomanip> +#include <ios> #include <iterator> #include <limits> #include <list> @@ -4089,6 +4090,13 @@ std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters( // Formats the given time in milliseconds as seconds. std::string FormatTimeInMillisAsSeconds(TimeInMillis ms) { ::std::stringstream ss; + // For the exact N seconds, makes sure output has a trailing decimal point. + // Sets precision so that we won't have many trailing zeros (e.g., 300 ms + // will be just 0.3, 410 ms 0.41, and so on) + ss << std::fixed + << std::setprecision( + ms % 1000 == 0 ? 0 : (ms % 100 == 0 ? 1 : (ms % 10 == 0 ? 2 : 3))) + << std::showpoint; ss << (static_cast<double>(ms) * 1e-3); return ss.str(); } |