Skip to content

Commit

Permalink
[gtest] Upgrade googletest to version 1.8.0, minimizing local changes.
Browse files Browse the repository at this point in the history
This required re-working the streaming support and lit's support for
'--gtest_list_tests' but otherwise seems to be a clean upgrade.

Differential Revision: https://reviews.llvm.org/D28154

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291029 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
chandlerc committed Jan 4, 2017
1 parent d240497 commit 4be13d6
Show file tree
Hide file tree
Showing 36 changed files with 5,451 additions and 2,462 deletions.
2 changes: 2 additions & 0 deletions cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ else()
endif()

check_cxx_compiler_flag("-Wno-variadic-macros" SUPPORTS_NO_VARIADIC_MACROS_FLAG)
check_cxx_compiler_flag("-Wno-gnu-zero-variadic-macro-arguments"
SUPPORTS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)

set(USE_NO_MAYBE_UNINITIALIZED 0)
set(USE_NO_UNINITIALIZED 0)
Expand Down
5 changes: 5 additions & 0 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
add_custom_target(UnitTests)
set_target_properties(UnitTests PROPERTIES FOLDER "Tests")

# Some parts of gtest rely on this GNU extension, don't warn on it.
if(SUPPORTS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
add_definitions("-Wno-gnu-zero-variadic-macro-arguments")
endif()

function(add_llvm_unittest test_dirname)
add_unittest(UnitTests ${test_dirname} ${ARGN})
endfunction()
Expand Down
8 changes: 7 additions & 1 deletion utils/lit/lit/formats/googletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ def getGTestTests(self, path, litConfig, localConfig):

nested_tests = []
for ln in lines:
if not ln.strip():
# The test name list includes trailing comments beginning with
# a '#' on some lines, so skip those. We don't support test names
# that use escaping to embed '#' into their name as the names come
# from C++ class and method names where such things are hard and
# uninteresting to support.
ln = ln.split('#', 1)[0].rstrip()
if not ln.lstrip():
continue

if 'Running main() from gtest_main.cc' in ln:
Expand Down
6 changes: 6 additions & 0 deletions utils/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ endif()
if(SUPPORTS_NO_VARIADIC_MACROS_FLAG)
add_definitions("-Wno-variadic-macros")
endif()
if(SUPPORTS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
add_definitions("-Wno-gnu-zero-variadic-macro-arguments")
endif()
if(CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG)
add_definitions("-Wno-covered-switch-default")
endif()

set(LLVM_REQUIRES_RTTI 1)
add_definitions( -DGTEST_HAS_RTTI=0 )
Expand Down
16 changes: 6 additions & 10 deletions utils/unittest/googletest/README.LLVM
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
LLVM notes
----------

This directory contains Google Test 1.6.0, with all elements removed except for
This directory contains Google Test 1.8.0, with all elements removed except for
the actual source code, to minimize the addition to the LLVM distribution.

Cleaned up as follows:

# Remove all the unnecessary files and directories
$ rm -f aclocal* CMakeLists.txt configure* Makefile* CHANGES CONTRIBUTORS README
$ rm -rf build-aux cmake codegear fused-src m4 make msvc samples scripts test xcode
$ rm -f CMakeLists.txt configure* Makefile* CHANGES CONTRIBUTORS README README.md .gitignore
$ rm -rf build-aux cmake codegear m4 make msvc samples scripts test xcode docs
$ rm -f `find . -name \*\.pump`
$ rm -f src/gtest_main.cc

# Put the license in the consistent place for LLVM.
$ mv COPYING LICENSE.TXT
$ mv LICENSE LICENSE.TXT

Modified as follows:
* Added support for FreeBSD.
* Added support for Minix (PR6797).
* To GTestStreamToHelper in include/gtest/internal/gtest-internal.h,
added the ability to stream with raw_os_ostream.
* To refresh Haiku support in include/gtest/internal/gtest-port.h,
see http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20100621/102898.html
* Added support for Minix and Haiku.
* Added raw_os_ostream support to include/gtest/internal/custom/gtest-printers.h.
17 changes: 14 additions & 3 deletions utils/unittest/googletest/include/gtest/gtest-death-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ GTEST_DECLARE_string_(death_test_style);

#if GTEST_HAS_DEATH_TEST

namespace internal {

// Returns a Boolean value indicating whether the caller is currently
// executing in the context of the death test child process. Tools such as
// Valgrind heap checkers may need this to modify their behavior in death
// tests. IMPORTANT: This is an internal utility. Using it may break the
// implementation of death tests. User code MUST NOT use it.
GTEST_API_ bool InDeathTestChild();

} // namespace internal

// The following macros are useful for writing death tests.

// Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is
Expand All @@ -75,7 +86,7 @@ GTEST_DECLARE_string_(death_test_style);
// for (int i = 0; i < 5; i++) {
// EXPECT_DEATH(server.ProcessRequest(i),
// "Invalid request .* in ProcessRequest()")
// << "Failed to die on request " << i);
// << "Failed to die on request " << i;
// }
//
// ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting");
Expand Down Expand Up @@ -245,10 +256,10 @@ class GTEST_API_ KilledBySignal {
# ifdef NDEBUG

# define EXPECT_DEBUG_DEATH(statement, regex) \
do { statement; } while (::testing::internal::AlwaysFalse())
GTEST_EXECUTE_STATEMENT_(statement, regex)

# define ASSERT_DEBUG_DEATH(statement, regex) \
do { statement; } while (::testing::internal::AlwaysFalse())
GTEST_EXECUTE_STATEMENT_(statement, regex)

# else

Expand Down
112 changes: 85 additions & 27 deletions utils/unittest/googletest/include/gtest/gtest-message.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,41 @@

#include <limits>

#include "gtest/internal/gtest-string.h"
#include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-port.h"

#if !GTEST_NO_LLVM_RAW_OSTREAM
#include "llvm/Support/raw_os_ostream.h"

// LLVM INTERNAL CHANGE: To allow operator<< to work with both
// std::ostreams and LLVM's raw_ostreams, we define a special
// std::ostream with an implicit conversion to raw_ostream& and stream
// to that. This causes the compiler to prefer std::ostream overloads
// but still find raw_ostream& overloads.
namespace llvm {
class convertible_fwd_ostream : public std::ostream {
raw_os_ostream ros_;

public:
convertible_fwd_ostream(std::ostream& os)
: std::ostream(os.rdbuf()), ros_(*this) {}
operator raw_ostream&() { return ros_; }
};
}
template <typename T>
inline void GTestStreamToHelper(std::ostream& os, const T& val) {
llvm::convertible_fwd_ostream cos(os);
cos << val;
}
#else
template <typename T>
inline void GTestStreamToHelper(std::ostream& os, const T& val) {
os << val;
}
#endif

// Ensures that there is at least one operator<< in the global namespace.
// See Message& operator<<(...) below for why.
void operator<<(const testing::internal::Secret&, int);

namespace testing {

Expand Down Expand Up @@ -87,15 +120,7 @@ class GTEST_API_ Message {

public:
// Constructs an empty Message.
// We allocate the stringstream separately because otherwise each use of
// ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's
// stack frame leading to huge stack frames in some cases; gcc does not reuse
// the stack space.
Message() : ss_(new ::std::stringstream) {
// By default, we want there to be enough precision when printing
// a double to a Message.
*ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
}
Message();

// Copy constructor.
Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT
Expand All @@ -118,7 +143,26 @@ class GTEST_API_ Message {
// Streams a non-pointer value to this object.
template <typename T>
inline Message& operator <<(const T& val) {
::GTestStreamToHelper(ss_.get(), val);
// Some libraries overload << for STL containers. These
// overloads are defined in the global namespace instead of ::std.
//
// C++'s symbol lookup rule (i.e. Koenig lookup) says that these
// overloads are visible in either the std namespace or the global
// namespace, but not other namespaces, including the testing
// namespace which Google Test's Message class is in.
//
// To allow STL containers (and other types that has a << operator
// defined in the global namespace) to be used in Google Test
// assertions, testing::Message must access the custom << operator
// from the global namespace. With this using declaration,
// overloads of << defined in the global namespace and those
// visible via Koenig lookup are both exposed in this function.
#if GTEST_NO_LLVM_RAW_OSTREAM
using ::operator <<;
*ss_ << val;
#else
::GTestStreamToHelper(*ss_, val);
#endif
return *this;
}

Expand All @@ -140,7 +184,11 @@ class GTEST_API_ Message {
if (pointer == NULL) {
*ss_ << "(null)";
} else {
::GTestStreamToHelper(ss_.get(), pointer);
#if GTEST_NO_LLVM_RAW_OSTREAM
*ss_ << pointer;
#else
::GTestStreamToHelper(*ss_, pointer);
#endif
}
return *this;
}
Expand All @@ -164,12 +212,8 @@ class GTEST_API_ Message {

// These two overloads allow streaming a wide C string to a Message
// using the UTF-8 encoding.
Message& operator <<(const wchar_t* wide_c_str) {
return *this << internal::String::ShowWideCString(wide_c_str);
}
Message& operator <<(wchar_t* wide_c_str) {
return *this << internal::String::ShowWideCString(wide_c_str);
}
Message& operator <<(const wchar_t* wide_c_str);
Message& operator <<(wchar_t* wide_c_str);

#if GTEST_HAS_STD_WSTRING
// Converts the given wide string to a narrow string using the UTF-8
Expand All @@ -183,13 +227,11 @@ class GTEST_API_ Message {
Message& operator <<(const ::wstring& wstr);
#endif // GTEST_HAS_GLOBAL_WSTRING

// Gets the text streamed to this object so far as a String.
// Gets the text streamed to this object so far as an std::string.
// Each '\0' character in the buffer is replaced with "\\0".
//
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
internal::String GetString() const {
return internal::StringStreamToString(ss_.get());
}
std::string GetString() const;

private:

Expand All @@ -199,16 +241,20 @@ class GTEST_API_ Message {
// decide between class template specializations for T and T*, so a
// tr1::type_traits-like is_pointer works, and we can overload on that.
template <typename T>
inline void StreamHelper(internal::true_type /*dummy*/, T* pointer) {
inline void StreamHelper(internal::true_type /*is_pointer*/, T* pointer) {
if (pointer == NULL) {
*ss_ << "(null)";
} else {
::GTestStreamToHelper(ss_.get(), pointer);
*ss_ << pointer;
}
}
template <typename T>
inline void StreamHelper(internal::false_type /*dummy*/, const T& value) {
::GTestStreamToHelper(ss_.get(), value);
inline void StreamHelper(internal::false_type /*is_pointer*/,
const T& value) {
// See the comments in Message& operator <<(const T&) above for why
// we need this using statement.
using ::operator <<;
*ss_ << value;
}
#endif // GTEST_OS_SYMBIAN

Expand All @@ -225,6 +271,18 @@ inline std::ostream& operator <<(std::ostream& os, const Message& sb) {
return os << sb.GetString();
}

namespace internal {

// Converts a streamable value to an std::string. A NULL pointer is
// converted to "(null)". When the input value is a ::string,
// ::std::string, ::wstring, or ::std::wstring object, each NUL
// character in it is replaced with "\\0".
template <typename T>
std::string StreamableToString(const T& streamable) {
return (Message() << streamable).GetString();
}

} // namespace internal
} // namespace testing

#endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
56 changes: 37 additions & 19 deletions utils/unittest/googletest/include/gtest/gtest-param-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ TEST_P(DerivedTest, DoesBlah) {
// inside #if GTEST_HAS_PARAM_TEST.
#include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-param-util.h"
#include "gtest/internal/gtest-param-util-generated.h"

#if GTEST_HAS_PARAM_TEST

Expand Down Expand Up @@ -324,12 +325,6 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
return ValuesIn(container.begin(), container.end());
}

} // namespace testing

#include <gtest/internal/gtest-param-util-generated.h>

namespace testing {

// Values() allows generating tests from explicitly specified list of
// parameters.
//
Expand Down Expand Up @@ -1262,7 +1257,7 @@ inline internal::ParamGenerator<bool> Bool() {
// Boolean flags:
//
// class FlagDependentTest
// : public testing::TestWithParam<tuple(bool, bool)> > {
// : public testing::TestWithParam<tuple<bool, bool> > {
// virtual void SetUp() {
// // Assigns external_flag_1 and external_flag_2 values from the tuple.
// tie(external_flag_1, external_flag_2) = GetParam();
Expand Down Expand Up @@ -1392,14 +1387,17 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
static int AddToRegistry() { \
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
GetTestCasePatternHolder<test_case_name>(\
#test_case_name, __FILE__, __LINE__)->AddTestPattern(\
#test_case_name, \
#test_name, \
new ::testing::internal::TestMetaFactory< \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \
#test_case_name, \
::testing::internal::CodeLocation(\
__FILE__, __LINE__))->AddTestPattern(\
#test_case_name, \
#test_name, \
new ::testing::internal::TestMetaFactory< \
GTEST_TEST_CLASS_NAME_(\
test_case_name, test_name)>()); \
return 0; \
} \
static int gtest_registering_dummy_; \
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
}; \
Expand All @@ -1408,16 +1406,36 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()

# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
// The optional last argument to INSTANTIATE_TEST_CASE_P allows the user
// to specify a function or functor that generates custom test name suffixes
// based on the test parameters. The function should accept one argument of
// type testing::TestParamInfo<class ParamType>, and return std::string.
//
// testing::PrintToStringParamName is a builtin test suffix generator that
// returns the value of testing::PrintToString(GetParam()). It does not work
// for std::string or C strings.
//
// Note: test names must be non-empty, unique, and may only contain ASCII
// alphanumeric characters or underscore.

# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \
::testing::internal::ParamGenerator<test_case_name::ParamType> \
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
int gtest_##prefix##test_case_name##_dummy_ = \
::std::string gtest_##prefix##test_case_name##_EvalGenerateName_( \
const ::testing::TestParamInfo<test_case_name::ParamType>& info) { \
return ::testing::internal::GetParamNameGen<test_case_name::ParamType> \
(__VA_ARGS__)(info); \
} \
int gtest_##prefix##test_case_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
GetTestCasePatternHolder<test_case_name>(\
#test_case_name, __FILE__, __LINE__)->AddTestCaseInstantiation(\
#prefix, \
&gtest_##prefix##test_case_name##_EvalGenerator_, \
__FILE__, __LINE__)
#test_case_name, \
::testing::internal::CodeLocation(\
__FILE__, __LINE__))->AddTestCaseInstantiation(\
#prefix, \
&gtest_##prefix##test_case_name##_EvalGenerator_, \
&gtest_##prefix##test_case_name##_EvalGenerateName_, \
__FILE__, __LINE__)

} // namespace testing

Expand Down
Loading

0 comments on commit 4be13d6

Please sign in to comment.