Skip to content

Commit

Permalink
Fix gmock_output_test when using MSVC
Browse files Browse the repository at this point in the history
std::pair is printed as "struct std::pair<int,bool>" when using MSVC
vs "std::pair<int,bool>" 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
  • Loading branch information
thughes authored and kunitoki committed Nov 4, 2023
1 parent c66a0a1 commit ea8cbe8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions googlemock/test/gmock_output_test_.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <stdio.h>

#include <string>
#include <tuple>

#include "gmock/gmock.h"
#include "gtest/gtest.h"
Expand Down Expand Up @@ -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<int> m1 = Ge(48);
EXPECT_THAT((std::pair<int, bool>(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<int,bool>" when using MSVC vs "std::pair<int,bool>" with
// other compilers.
EXPECT_THAT((std::tuple<int, bool>(42, true)), IsPair(m1, true));
}

void TestCatchesLeakedMocksInAdHocTests() {
Expand Down
4 changes: 2 additions & 2 deletions googlemock/test/gmock_output_test_golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ Stack trace:
[ OK ] GMockOutputTest.CatchesLeakedMocks
[ RUN ] GMockOutputTest.PrintsMatcher
FILE:#: Failure
Value of: (std::pair<int, bool>(42, true))
Value of: (std::tuple<int, bool>(42, true))
Expected: is pair (first: is >= 48, second: true)
Actual: (42, true) (of type std::pair<int, bool>)
Actual: (42, true)
[ FAILED ] GMockOutputTest.PrintsMatcher
[ FAILED ] GMockOutputTest.UnexpectedCall
[ FAILED ] GMockOutputTest.UnexpectedCallToVoidFunction
Expand Down

0 comments on commit ea8cbe8

Please sign in to comment.