summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@google.com>2023-02-21 18:24:42 (GMT)
committerCopybara-Service <copybara-worker@google.com>2023-02-21 18:25:39 (GMT)
commit750d67d809700ae8fca6d610f7b41b71aa161808 (patch)
tree829ffd1c82c56ee3d89d56d746b73769ee443068
parent7a7231c442484be389fdf01594310349ca0e42a8 (diff)
downloadgoogletest-750d67d809700ae8fca6d610f7b41b71aa161808.zip
googletest-750d67d809700ae8fca6d610f7b41b71aa161808.tar.gz
googletest-750d67d809700ae8fca6d610f7b41b71aa161808.tar.bz2
Remove int64_t cast in RecordProperty
Historically, calls to RecordProperty with values that are convertible to int64_t have been casted to int64_t. The result was that types like float or double would be truncated when printed (e.g., 4.75 -> 4). This change removes the cast so that the types are printed in a more appropriate manner. PiperOrigin-RevId: 511238685 Change-Id: I80de5db14462da2a3e1f476086025ae514383a17
-rw-r--r--googletest/include/gtest/gtest.h2
-rw-r--r--googletest/test/googletest-json-outfiles-test.py10
-rw-r--r--googletest/test/gtest_xml_outfile2_test_.cc4
-rwxr-xr-xgoogletest/test/gtest_xml_outfiles_test.py10
4 files changed, 12 insertions, 14 deletions
diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h
index 35c0802..6fdf552 100644
--- a/googletest/include/gtest/gtest.h
+++ b/googletest/include/gtest/gtest.h
@@ -302,7 +302,7 @@ class GTEST_API_ Test {
template <typename T, std::enable_if_t<std::is_convertible<T, int64_t>::value,
bool> = true>
static void RecordProperty(const std::string& key, const T& value) {
- RecordProperty(key, (Message() << static_cast<int64_t>(value)).GetString());
+ RecordProperty(key, (Message() << value).GetString());
}
protected:
diff --git a/googletest/test/googletest-json-outfiles-test.py b/googletest/test/googletest-json-outfiles-test.py
index 83a56de..ff15722 100644
--- a/googletest/test/googletest-json-outfiles-test.py
+++ b/googletest/test/googletest-json-outfiles-test.py
@@ -88,7 +88,7 @@ EXPECTED_2 = {
'time': '*',
'timestamp': '*',
'testsuite': [{
- 'name': 'TestInt64Properties',
+ 'name': 'TestInt64ConvertibleProperties',
'file': 'gtest_xml_outfile2_test_.cc',
'line': 41,
'status': 'RUN',
@@ -97,11 +97,11 @@ EXPECTED_2 = {
'time': '*',
'classname': 'PropertyTwo',
'SetUpProp': '2',
- 'TestFloatProperty': '3',
- 'TestDoubleProperty': '4',
+ 'TestFloatProperty': '3.25',
+ 'TestDoubleProperty': '4.75',
'TestSizetProperty': '5',
- 'TestBoolProperty': '1',
- 'TestCharProperty': '65',
+ 'TestBoolProperty': 'true',
+ 'TestCharProperty': 'A',
'TestInt16Property': '6',
'TestInt32Property': '7',
'TestInt64Property': '8',
diff --git a/googletest/test/gtest_xml_outfile2_test_.cc b/googletest/test/gtest_xml_outfile2_test_.cc
index 5ee216d..ed58dc8 100644
--- a/googletest/test/gtest_xml_outfile2_test_.cc
+++ b/googletest/test/gtest_xml_outfile2_test_.cc
@@ -38,9 +38,7 @@ class PropertyTwo : public testing::Test {
void TearDown() override { RecordProperty("TearDownProp", 2); }
};
-TEST_F(PropertyTwo, TestInt64Properties) {
- // Floats and doubles are written as int64_t, so we test that the values
- // written are truncated to int64_t.
+TEST_F(PropertyTwo, TestInt64ConvertibleProperties) {
float float_prop = 3.25;
RecordProperty("TestFloatProperty", float_prop);
diff --git a/googletest/test/gtest_xml_outfiles_test.py b/googletest/test/gtest_xml_outfiles_test.py
index 7ee0f3c..50291b0 100755
--- a/googletest/test/gtest_xml_outfiles_test.py
+++ b/googletest/test/gtest_xml_outfiles_test.py
@@ -57,14 +57,14 @@ EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
<testsuite name="PropertyTwo" tests="1" failures="0" skipped="0" disabled="0" errors="0" time="*" timestamp="*">
- <testcase name="TestInt64Properties" file="gtest_xml_outfile2_test_.cc" line="41" status="run" result="completed" time="*" timestamp="*" classname="PropertyTwo">
+ <testcase name="TestInt64ConvertibleProperties" file="gtest_xml_outfile2_test_.cc" line="41" status="run" result="completed" time="*" timestamp="*" classname="PropertyTwo">
<properties>
<property name="SetUpProp" value="2"/>
- <property name="TestFloatProperty" value="3"/>
- <property name="TestDoubleProperty" value="4"/>
+ <property name="TestFloatProperty" value="3.25"/>
+ <property name="TestDoubleProperty" value="4.75"/>
<property name="TestSizetProperty" value="5"/>
- <property name="TestBoolProperty" value="1"/>
- <property name="TestCharProperty" value="65"/>
+ <property name="TestBoolProperty" value="true"/>
+ <property name="TestCharProperty" value="A"/>
<property name="TestInt16Property" value="6"/>
<property name="TestInt32Property" value="7"/>
<property name="TestInt64Property" value="8"/>