Skip to content

Commit 0a3b403

Browse files
thughescopybara-github
authored andcommitted
Fix gmock_output_test when using MSVC
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
1 parent d925117 commit 0a3b403

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

googlemock/test/gmock_output_test_.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <stdio.h>
3434

3535
#include <string>
36+
#include <tuple>
3637

3738
#include "gmock/gmock.h"
3839
#include "gtest/gtest.h"
@@ -254,12 +255,16 @@ TEST_F(GMockOutputTest, CatchesLeakedMocks) {
254255
}
255256

256257
MATCHER_P2(IsPair, first, second, "") {
257-
return Value(arg.first, first) && Value(arg.second, second);
258+
return Value(std::get<0>(arg), first) && Value(std::get<1>(arg), second);
258259
}
259260

260261
TEST_F(GMockOutputTest, PrintsMatcher) {
261262
const testing::Matcher<int> m1 = Ge(48);
262-
EXPECT_THAT((std::pair<int, bool>(42, true)), IsPair(m1, true));
263+
// Explicitly using std::tuple instead of std::pair due to differences between
264+
// MSVC and other compilers. std::pair is printed as
265+
// "struct std::pair<int,bool>" when using MSVC vs "std::pair<int,bool>" with
266+
// other compilers.
267+
EXPECT_THAT((std::tuple<int, bool>(42, true)), IsPair(m1, true));
263268
}
264269

265270
void TestCatchesLeakedMocksInAdHocTests() {

googlemock/test/gmock_output_test_golden.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ Stack trace:
290290
[ OK ] GMockOutputTest.CatchesLeakedMocks
291291
[ RUN ] GMockOutputTest.PrintsMatcher
292292
FILE:#: Failure
293-
Value of: (std::pair<int, bool>(42, true))
293+
Value of: (std::tuple<int, bool>(42, true))
294294
Expected: is pair (first: is >= 48, second: true)
295-
Actual: (42, true) (of type std::pair<int, bool>)
295+
Actual: (42, true)
296296
[ FAILED ] GMockOutputTest.PrintsMatcher
297297
[ FAILED ] GMockOutputTest.UnexpectedCall
298298
[ FAILED ] GMockOutputTest.UnexpectedCallToVoidFunction

0 commit comments

Comments
 (0)