From 0a3b403fe037ff80daa1826ae99eed41e94dea05 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 1 Feb 2023 09:32:33 -0800 Subject: Fix gmock_output_test when using MSVC std::pair is printed as "struct std::pair" when using MSVC vs "std::pair" with other compilers. Switch to "std::tuple", which is the same for all compilers. See https://learn.microsoft.com/en-us/cpp/standard-library/pair-structure https://learn.microsoft.com/en-us/cpp/standard-library/tuple-class PiperOrigin-RevId: 506340295 Change-Id: Ib4ce2f74d54888a4e4173f42da1b55cc5583f7d4 --- googlemock/test/gmock_output_test_.cc | 9 +++++++-- googlemock/test/gmock_output_test_golden.txt | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index af4eaa9..ca5a646 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -33,6 +33,7 @@ #include #include +#include #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -254,12 +255,16 @@ TEST_F(GMockOutputTest, CatchesLeakedMocks) { } MATCHER_P2(IsPair, first, second, "") { - return Value(arg.first, first) && Value(arg.second, second); + return Value(std::get<0>(arg), first) && Value(std::get<1>(arg), second); } TEST_F(GMockOutputTest, PrintsMatcher) { const testing::Matcher m1 = Ge(48); - EXPECT_THAT((std::pair(42, true)), IsPair(m1, true)); + // Explicitly using std::tuple instead of std::pair due to differences between + // MSVC and other compilers. std::pair is printed as + // "struct std::pair" when using MSVC vs "std::pair" with + // other compilers. + EXPECT_THAT((std::tuple(42, true)), IsPair(m1, true)); } void TestCatchesLeakedMocksInAdHocTests() { diff --git a/googlemock/test/gmock_output_test_golden.txt b/googlemock/test/gmock_output_test_golden.txt index 467fa20..ac2a5e2 100644 --- a/googlemock/test/gmock_output_test_golden.txt +++ b/googlemock/test/gmock_output_test_golden.txt @@ -290,9 +290,9 @@ Stack trace: [ OK ] GMockOutputTest.CatchesLeakedMocks [ RUN ] GMockOutputTest.PrintsMatcher FILE:#: Failure -Value of: (std::pair(42, true)) +Value of: (std::tuple(42, true)) Expected: is pair (first: is >= 48, second: true) - Actual: (42, true) (of type std::pair) + Actual: (42, true) [ FAILED ] GMockOutputTest.PrintsMatcher [ FAILED ] GMockOutputTest.UnexpectedCall [ FAILED ] GMockOutputTest.UnexpectedCallToVoidFunction -- cgit v0.12