summaryrefslogtreecommitdiff
path: root/googletest
diff options
context:
space:
mode:
authorYonggang Luo <luoyonggang@gmail.com>2022-11-24 23:54:19 +0800
committerYonggang Luo <luoyonggang@gmail.com>2023-03-01 00:13:32 +0800
commit6f1c4b3d7b139c7217698bf4115be9f40785f661 (patch)
tree32bbb2bec79d733bf34f3b258d8ab2db4bc92163 /googletest
parent097f64e98693500d44d022a781745e562aa492ad (diff)
downloadgoogletest-git-6f1c4b3d7b139c7217698bf4115be9f40785f661.tar.gz
Fixes the test gmock_output_test.py with MSVC
For MSVC, gmock_output_test.py output struct std::pair<int,bool>, for GCC, it's output std::pair<int, bool>, it's not the same, my intention is getting these to be same by removing struct for MSVC's outptu, and strip redundant space for GCC. As a by-product, ``` #ifdef _MSC_VER #define ERROR_DESC "class std::runtime_error" #else #define ERROR_DESC "std::runtime_error" #endif ``` can be simplified to ``` #define ERROR_DESC "std::runtime_error" ``` Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Diffstat (limited to 'googletest')
-rw-r--r--googletest/include/gtest/internal/gtest-type-util.h30
-rw-r--r--googletest/test/gtest_unittest.cc4
2 files changed, 30 insertions, 4 deletions
diff --git a/googletest/include/gtest/internal/gtest-type-util.h b/googletest/include/gtest/internal/gtest-type-util.h
index 17a470b6..b23ad559 100644
--- a/googletest/include/gtest/internal/gtest-type-util.h
+++ b/googletest/include/gtest/internal/gtest-type-util.h
@@ -67,6 +67,22 @@ inline std::string CanonicalizeForStdLibVersioning(std::string s) {
s.erase(strlen("std"), end - strlen("std"));
}
}
+
+ /* Strip redundant spaces in typename to match MSVC */
+ /* For example, std::pair<int, bool> -> std::pair<int,bool> */
+ static const char to_search[] = ", ";
+ static const char replace_str[] = ",";
+ size_t pos = 0;
+ while (true) {
+ // Get the next occurrence from the current position
+ pos = s.find(to_search, pos);
+ if (pos == std::string::npos) {
+ break;
+ }
+ // Replace this occurrence of substring
+ s.replace(pos, strlen(to_search), replace_str);
+ pos += strlen(replace_str);
+ }
return s;
}
@@ -85,6 +101,20 @@ inline std::string GetTypeName(const std::type_info& type) {
const std::string name_str(status == 0 ? readable_name : name);
free(readable_name);
return CanonicalizeForStdLibVersioning(name_str);
+#elif defined(_MSC_VER)
+ // Strip struct and class due to differences between
+ // MSVC and other compilers. std::pair<int,bool> is printed as
+ // "struct std::pair<int,bool>" when using MSVC vs "std::pair<int, bool>" with
+ // other compilers.
+ std::string s = name;
+ // Only strip the leading "struct " and "class ", so uses rfind == 0 to
+ // ensure that
+ if (s.rfind("struct ", 0) == 0) {
+ s = s.substr(strlen("struct "));
+ } else if (s.rfind("class ", 0) == 0) {
+ s = s.substr(strlen("class "));
+ }
+ return s;
#else
return name;
#endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc
index ecffa376..180c3abe 100644
--- a/googletest/test/gtest_unittest.cc
+++ b/googletest/test/gtest_unittest.cc
@@ -3314,11 +3314,7 @@ TEST_F(SingleEvaluationTest, OtherCases) {
#if GTEST_HAS_RTTI
-#ifdef _MSC_VER
-#define ERROR_DESC "class std::runtime_error"
-#else
#define ERROR_DESC "std::runtime_error"
-#endif
#else // GTEST_HAS_RTTI