Skip to content

Commit

Permalink
Fix tests with VS2015 and VS2017
Browse files Browse the repository at this point in the history
  • Loading branch information
KindDragon committed May 3, 2017
1 parent 215a739 commit c3685ac
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 15 deletions.
13 changes: 13 additions & 0 deletions .gitignore
@@ -1,2 +1,15 @@
# Ignore CI build directory
build/
_build/

# Visual Studio files
*.sdf
*.opensdf
*.VC.opendb
*.suo
*.user
_ReSharper.Caches/
Win32-Debug/
Win32-Release/
x64-Debug/
x64-Release/
8 changes: 4 additions & 4 deletions googlemock/test/gmock-generated-matchers_test.cc
Expand Up @@ -121,21 +121,21 @@ TEST(ArgsTest, AcceptsOneTemplateArg) {
}

TEST(ArgsTest, AcceptsTwoTemplateArgs) {
const tuple<short, int, long> t(4, 5, 6L); // NOLINT
const tuple<short, int, long> t(static_cast<short>(4), 5, 6L); // NOLINT

EXPECT_THAT(t, (Args<0, 1>(Lt())));
EXPECT_THAT(t, (Args<1, 2>(Lt())));
EXPECT_THAT(t, Not(Args<0, 2>(Gt())));
}

TEST(ArgsTest, AcceptsRepeatedTemplateArgs) {
const tuple<short, int, long> t(4, 5, 6L); // NOLINT
const tuple<short, int, long> t(static_cast<short>(4), 5, 6L); // NOLINT
EXPECT_THAT(t, (Args<0, 0>(Eq())));
EXPECT_THAT(t, Not(Args<1, 1>(Ne())));
}

TEST(ArgsTest, AcceptsDecreasingTemplateArgs) {
const tuple<short, int, long> t(4, 5, 6L); // NOLINT
const tuple<short, int, long> t(static_cast<short>(4), 5, 6L); // NOLINT
EXPECT_THAT(t, (Args<2, 0>(Gt())));
EXPECT_THAT(t, Not(Args<2, 1>(Lt())));
}
Expand All @@ -160,7 +160,7 @@ TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) {
}

TEST(ArgsTest, CanBeNested) {
const tuple<short, int, long, int> t(4, 5, 6L, 6); // NOLINT
const tuple<short, int, long, int> t(static_cast<short>(4), 5, 6L, 6); // NOLINT
EXPECT_THAT(t, (Args<1, 2, 3>(Args<1, 2>(Eq()))));
EXPECT_THAT(t, (Args<0, 1, 3>(Args<0, 2>(Lt()))));
}
Expand Down
5 changes: 5 additions & 0 deletions googlemock/test/gmock-matchers_test.cc
Expand Up @@ -58,6 +58,11 @@
# include <forward_list> // NOLINT
#endif

// Disable MSVC2015 warning for std::pair: "decorated name length exceeded, name was truncated".
#if defined(_MSC_VER) && (_MSC_VER == 1900)
# pragma warning(disable:4503)
#endif

namespace testing {

namespace internal {
Expand Down
2 changes: 0 additions & 2 deletions googletest/cmake/internal_utils.cmake
Expand Up @@ -81,8 +81,6 @@ macro(config_compiler_and_linker)
# Suppress "unreachable code" warning on VS 2012 and later.
# http://stackoverflow.com/questions/3232669 explains the issue.
set(cxx_base_flags "${cxx_base_flags} -wd4702")
endif()
if (NOT (MSVC_VERSION GREATER 1900)) # 1900 is Visual Studio 2015
# BigObj required for tests.
set(cxx_base_flags "${cxx_base_flags} -bigobj")
endif()
Expand Down
47 changes: 39 additions & 8 deletions googletest/test/gtest-printers_test.cc
Expand Up @@ -51,10 +51,15 @@
#include "gtest/gtest.h"

// hash_map and hash_set are available under Visual C++, or on Linux.
#if GTEST_HAS_HASH_MAP_
#if GTEST_HAS_UNORDERED_MAP_
# include <unordered_map> // NOLINT
#elif GTEST_HAS_HASH_MAP_
# include <hash_map> // NOLINT
#endif // GTEST_HAS_HASH_MAP_
#if GTEST_HAS_HASH_SET_

#if GTEST_HAS_UNORDERED_SET_
# include <unordered_set> // NOLINT
#elif GTEST_HAS_HASH_SET_
# include <hash_set> // NOLINT
#endif // GTEST_HAS_HASH_SET_

Expand Down Expand Up @@ -216,21 +221,47 @@ using ::testing::internal::UniversalTersePrintTupleFieldsToStrings;
#endif
using ::testing::internal::string;

#if GTEST_HAS_HASH_MAP_
// The hash_* classes are not part of the C++ standard. STLport
// defines them in namespace std. MSVC defines them in ::stdext. GCC
// defines them in ::.
#if GTEST_HAS_UNORDERED_MAP_

#define GTEST_HAS_HASH_MAP_ 1
template<class Key, class T>
using hash_map = ::std::unordered_map<Key, T>;
template<class Key, class T>
using hash_multimap = ::std::unordered_multimap<Key, T>;

#elif GTEST_HAS_HASH_MAP_

#ifdef _STLP_HASH_MAP // We got <hash_map> from STLport.
using ::std::hash_map;
using ::std::hash_set;
using ::std::hash_multimap;
using ::std::hash_multiset;
#elif _MSC_VER
using ::stdext::hash_map;
using ::stdext::hash_set;
using ::stdext::hash_multimap;
#endif

#endif

#if GTEST_HAS_UNORDERED_SET_

#define GTEST_HAS_HASH_SET_ 1
template<class Key>
using hash_set = ::std::unordered_set<Key>;
template<class Key>
using hash_multiset = ::std::unordered_multiset<Key>;

#elif GTEST_HAS_HASH_SET_

#ifdef _STLP_HASH_MAP // We got <hash_map> from STLport.
using ::std::hash_set;
using ::std::hash_multiset;
#elif _MSC_VER
using ::stdext::hash_set;
using ::stdext::hash_multiset;
#endif

#endif

// Prints a value to a string using the universal value printer. This
Expand Down Expand Up @@ -1040,7 +1071,7 @@ TEST(PrintTr1TupleTest, VariousSizes) {
// an explicit type cast of NULL to be used.
::std::tr1::tuple<bool, char, short, testing::internal::Int32, // NOLINT
testing::internal::Int64, float, double, const char*, void*, string>
t10(false, 'a', 3, 4, 5, 1.5F, -2.5, str,
t10(false, 'a', static_cast<short>(3), 4, 5, 1.5F, -2.5, str,
ImplicitCast_<void*>(NULL), "10");
EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
" pointing to \"8\", NULL, \"10\")",
Expand Down Expand Up @@ -1099,7 +1130,7 @@ TEST(PrintStdTupleTest, VariousSizes) {
// an explicit type cast of NULL to be used.
::std::tuple<bool, char, short, testing::internal::Int32, // NOLINT
testing::internal::Int64, float, double, const char*, void*, string>
t10(false, 'a', 3, 4, 5, 1.5F, -2.5, str,
t10(false, 'a', static_cast<short>(3), 4, 5, 1.5F, -2.5, str,
ImplicitCast_<void*>(NULL), "10");
EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
" pointing to \"8\", NULL, \"10\")",
Expand Down
2 changes: 1 addition & 1 deletion googletest/test/gtest_catch_exceptions_test_.cc
Expand Up @@ -138,7 +138,7 @@ TEST_F(CxxExceptionInConstructorTest, ThrowsExceptionInConstructor) {
}

// Exceptions in destructors are not supported in C++11.
#if !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L && _MSC_VER < 1900
#if !GTEST_LANG_CXX11
class CxxExceptionInDestructorTest : public Test {
public:
static void TearDownTestCase() {
Expand Down

0 comments on commit c3685ac

Please sign in to comment.