Unverified Commit d4f77c1e authored by Gennadiy Civil's avatar Gennadiy Civil Committed by GitHub
Browse files

Merge branch 'master' into win-libcxx2

parents 3498a1ac ac34e6c9
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <string> #include <string>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gtest/internal/custom/gtest.h"
#if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) #if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
...@@ -51,9 +52,9 @@ void TestInitGoogleMock(const Char* (&argv)[M], const Char* (&new_argv)[N], ...@@ -51,9 +52,9 @@ void TestInitGoogleMock(const Char* (&argv)[M], const Char* (&new_argv)[N],
const ::std::string& expected_gmock_verbose) { const ::std::string& expected_gmock_verbose) {
const ::std::string old_verbose = GMOCK_FLAG(verbose); const ::std::string old_verbose = GMOCK_FLAG(verbose);
int argc = M; int argc = M - 1;
InitGoogleMock(&argc, const_cast<Char**>(argv)); InitGoogleMock(&argc, const_cast<Char**>(argv));
ASSERT_EQ(N, argc) << "The new argv has wrong number of elements."; ASSERT_EQ(N - 1, argc) << "The new argv has wrong number of elements.";
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
EXPECT_STREQ(new_argv[i], argv[i]); EXPECT_STREQ(new_argv[i], argv[i]);
......
#!/usr/bin/env python
#
# Copyright 2006, Google Inc. # Copyright 2006, Google Inc.
# All rights reserved. # All rights reserved.
# #
...@@ -36,19 +34,19 @@ __author__ = 'wan@google.com (Zhanyong Wan)' ...@@ -36,19 +34,19 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
import os import os
import sys import sys
# Determines path to gtest_test_utils and imports it. # Determines path to gtest_test_utils and imports it.
SCRIPT_DIR = os.path.dirname(__file__) or '.' SCRIPT_DIR = os.path.dirname(__file__) or '.'
# isdir resolves symbolic links. # isdir resolves symbolic links.
gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../gtest/test') gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../googletest/test')
if os.path.isdir(gtest_tests_util_dir): if os.path.isdir(gtest_tests_util_dir):
GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir
else: else:
GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../gtest/test') GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../googletest/test')
sys.path.append(GTEST_TESTS_UTIL_DIR) sys.path.append(GTEST_TESTS_UTIL_DIR)
import gtest_test_utils # pylint: disable-msg=C6204
# pylint: disable=C6204
import gtest_test_utils
def GetSourceDir(): def GetSourceDir():
......
...@@ -95,6 +95,9 @@ macro(config_compiler_and_linker) ...@@ -95,6 +95,9 @@ macro(config_compiler_and_linker)
set(cxx_no_rtti_flags "-GR-") set(cxx_no_rtti_flags "-GR-")
elseif (CMAKE_COMPILER_IS_GNUCXX) elseif (CMAKE_COMPILER_IS_GNUCXX)
set(cxx_base_flags "-Wall -Wshadow -Werror") set(cxx_base_flags "-Wall -Wshadow -Werror")
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0)
set(cxx_base_flags "${cxx_base_flags} -Wno-error=dangling-else")
endif()
set(cxx_exception_flags "-fexceptions") set(cxx_exception_flags "-fexceptions")
set(cxx_no_exception_flags "-fno-exceptions") set(cxx_no_exception_flags "-fno-exceptions")
# Until version 4.3.2, GCC doesn't define a macro to indicate # Until version 4.3.2, GCC doesn't define a macro to indicate
......
...@@ -872,13 +872,33 @@ TEST(FooTest, Bar) { ...@@ -872,13 +872,33 @@ TEST(FooTest, Bar) {
} }
``` ```
Since we don't use exceptions, it is technically impossible to To alleviate this, gUnit provides three different solutions. You could use
implement the intended behavior here. To alleviate this, Google Test either exceptions, the `(ASSERT|EXPECT)_NO_FATAL_FAILURE` assertions or the
provides two solutions. You could use either the
`(ASSERT|EXPECT)_NO_FATAL_FAILURE` assertions or the
`HasFatalFailure()` function. They are described in the following two `HasFatalFailure()` function. They are described in the following two
subsections. subsections.
#### Asserting on Subroutines with an exception
The following code can turn ASSERT-failure into an exception:
```c++
class ThrowListener : public testing::EmptyTestEventListener {
void OnTestPartResult(const testing::TestPartResult& result) override {
if (result.type() == testing::TestPartResult::kFatalFailure) {
throw testing::AssertionException(result);
}
}
};
int main(int argc, char** argv) {
...
testing::UnitTest::GetInstance()->listeners().Append(new ThrowListener);
return RUN_ALL_TESTS();
}
```
This listener should be added after other listeners if you have any, otherwise
they won't see failed `OnTestPartResult`.
### Asserting on Subroutines ### ### Asserting on Subroutines ###
As shown above, if your test calls a subroutine that has an `ASSERT_*` As shown above, if your test calls a subroutine that has an `ASSERT_*`
......
...@@ -12,5 +12,5 @@ the respective git branch/tag).** ...@@ -12,5 +12,5 @@ the respective git branch/tag).**
To contribute code to Google Test, read: To contribute code to Google Test, read:
* [CONTRIBUTING](../CONTRIBUTING.md) -- read this _before_ writing your first patch. * [CONTRIBUTING](../../CONTRIBUTING.md) -- read this _before_ writing your first patch.
* [PumpManual](PumpManual.md) -- how we generate some of Google Test's source files. * [PumpManual](PumpManual.md) -- how we generate some of Google Test's source files.
...@@ -460,7 +460,7 @@ following benefits: ...@@ -460,7 +460,7 @@ following benefits:
You may still want to use `SetUp()/TearDown()` in the following rare cases: You may still want to use `SetUp()/TearDown()` in the following rare cases:
* If the tear-down operation could throw an exception, you must use `TearDown()` as opposed to the destructor, as throwing in a destructor leads to undefined behavior and usually will kill your program right away. Note that many standard libraries (like STL) may throw when exceptions are enabled in the compiler. Therefore you should prefer `TearDown()` if you want to write portable tests that work with or without exceptions. * If the tear-down operation could throw an exception, you must use `TearDown()` as opposed to the destructor, as throwing in a destructor leads to undefined behavior and usually will kill your program right away. Note that many standard libraries (like STL) may throw when exceptions are enabled in the compiler. Therefore you should prefer `TearDown()` if you want to write portable tests that work with or without exceptions.
* The assertion macros throw an exception when flag `--gtest_throw_on_failure` is specified. Therefore, you shouldn't use Google Test assertions in a destructor if you plan to run your tests with this flag. * The assertion macros throw an exception when flag `--gtest_throw_on_failure` is specified. Therefore, you shouldn't use Google Test assertions in a destructor if you plan to run your tests with this flag.
* In a constructor or destructor, you cannot make a virtual function call on this object. (You can call a method declared as virtual, but it will be statically bound.) Therefore, if you need to call a method that will be overriden in a derived class, you have to use `SetUp()/TearDown()`. * In a constructor or destructor, you cannot make a virtual function call on this object. (You can call a method declared as virtual, but it will be statically bound.) Therefore, if you need to call a method that will be overridden in a derived class, you have to use `SetUp()/TearDown()`.
## The compiler complains "no matching function to call" when I use ASSERT\_PREDn. How do I fix it? ## ## The compiler complains "no matching function to call" when I use ASSERT\_PREDn. How do I fix it? ##
......
...@@ -239,7 +239,7 @@ To create a test: ...@@ -239,7 +239,7 @@ To create a test:
1. The test's result is determined by the assertions; if any assertion in the test fails (either fatally or non-fatally), or if the test crashes, the entire test fails. Otherwise, it succeeds. 1. The test's result is determined by the assertions; if any assertion in the test fails (either fatally or non-fatally), or if the test crashes, the entire test fails. Otherwise, it succeeds.
``` ```
TEST(test_case_name, test_name) { TEST(testCaseName, testName) {
... test body ... ... test body ...
} }
``` ```
......
...@@ -46,6 +46,10 @@ ...@@ -46,6 +46,10 @@
// 2. operator<<(ostream&, const T&) defined in either foo or the // 2. operator<<(ostream&, const T&) defined in either foo or the
// global namespace. // global namespace.
// //
// However if T is an STL-style container then it is printed element-wise
// unless foo::PrintTo(const T&, ostream*) is defined. Note that
// operator<<() is ignored for container types.
//
// If none of the above is defined, it will print the debug string of // If none of the above is defined, it will print the debug string of
// the value if it is a protocol buffer, or print the raw bytes in the // the value if it is a protocol buffer, or print the raw bytes in the
// value otherwise. // value otherwise.
...@@ -107,6 +111,11 @@ ...@@ -107,6 +111,11 @@
# include <tuple> # include <tuple>
#endif #endif
#if GTEST_HAS_ABSL
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#endif // GTEST_HAS_ABSL
namespace testing { namespace testing {
// Definitions in the 'internal' and 'internal2' name spaces are // Definitions in the 'internal' and 'internal2' name spaces are
...@@ -125,6 +134,10 @@ enum TypeKind { ...@@ -125,6 +134,10 @@ enum TypeKind {
kProtobuf, // a protobuf type kProtobuf, // a protobuf type
kConvertibleToInteger, // a type implicitly convertible to BiggestInt kConvertibleToInteger, // a type implicitly convertible to BiggestInt
// (e.g. a named or unnamed enum type) // (e.g. a named or unnamed enum type)
#if GTEST_HAS_ABSL
kConvertibleToStringView, // a type implicitly convertible to
// absl::string_view
#endif
kOtherType // anything else kOtherType // anything else
}; };
...@@ -138,7 +151,7 @@ class TypeWithoutFormatter { ...@@ -138,7 +151,7 @@ class TypeWithoutFormatter {
// This default version is called when kTypeKind is kOtherType. // This default version is called when kTypeKind is kOtherType.
static void PrintValue(const T& value, ::std::ostream* os) { static void PrintValue(const T& value, ::std::ostream* os) {
PrintBytesInObjectTo(static_cast<const unsigned char*>( PrintBytesInObjectTo(static_cast<const unsigned char*>(
reinterpret_cast<const void *>(&value)), reinterpret_cast<const void*>(&value)),
sizeof(value), os); sizeof(value), os);
} }
}; };
...@@ -176,6 +189,19 @@ class TypeWithoutFormatter<T, kConvertibleToInteger> { ...@@ -176,6 +189,19 @@ class TypeWithoutFormatter<T, kConvertibleToInteger> {
} }
}; };
#if GTEST_HAS_ABSL
template <typename T>
class TypeWithoutFormatter<T, kConvertibleToStringView> {
public:
// Since T has neither operator<< nor PrintTo() but can be implicitly
// converted to absl::string_view, we print it as a absl::string_view.
//
// Note: the implementation is further below, as it depends on
// internal::PrintTo symbol which is defined later in the file.
static void PrintValue(const T& value, ::std::ostream* os);
};
#endif
// Prints the given value to the given ostream. If the value is a // Prints the given value to the given ostream. If the value is a
// protocol message, its debug string is printed; if it's an enum or // protocol message, its debug string is printed; if it's an enum or
// of a type implicitly convertible to BiggestInt, it's printed as an // of a type implicitly convertible to BiggestInt, it's printed as an
...@@ -203,10 +229,19 @@ class TypeWithoutFormatter<T, kConvertibleToInteger> { ...@@ -203,10 +229,19 @@ class TypeWithoutFormatter<T, kConvertibleToInteger> {
template <typename Char, typename CharTraits, typename T> template <typename Char, typename CharTraits, typename T>
::std::basic_ostream<Char, CharTraits>& operator<<( ::std::basic_ostream<Char, CharTraits>& operator<<(
::std::basic_ostream<Char, CharTraits>& os, const T& x) { ::std::basic_ostream<Char, CharTraits>& os, const T& x) {
TypeWithoutFormatter<T, TypeWithoutFormatter<T, (internal::IsAProtocolMessage<T>::value
(internal::IsAProtocolMessage<T>::value ? kProtobuf : ? kProtobuf
internal::ImplicitlyConvertible<const T&, internal::BiggestInt>::value ? : internal::ImplicitlyConvertible<
kConvertibleToInteger : kOtherType)>::PrintValue(x, &os); const T&, internal::BiggestInt>::value
? kConvertibleToInteger
:
#if GTEST_HAS_ABSL
internal::ImplicitlyConvertible<
const T&, absl::string_view>::value
? kConvertibleToStringView
:
#endif
kOtherType)>::PrintValue(x, &os);
return os; return os;
} }
...@@ -427,7 +462,8 @@ void DefaultPrintTo(WrapPrinterType<kPrintFunctionPointer> /* dummy */, ...@@ -427,7 +462,8 @@ void DefaultPrintTo(WrapPrinterType<kPrintFunctionPointer> /* dummy */,
*os << "NULL"; *os << "NULL";
} else { } else {
// T is a function type, so '*os << p' doesn't do what we want // T is a function type, so '*os << p' doesn't do what we want
// (it just prints p as bool). Cast p to const void* to print it. // (it just prints p as bool). We want to print p as a const
// void*.
*os << reinterpret_cast<const void*>(p); *os << reinterpret_cast<const void*>(p);
} }
} }
...@@ -456,17 +492,15 @@ void PrintTo(const T& value, ::std::ostream* os) { ...@@ -456,17 +492,15 @@ void PrintTo(const T& value, ::std::ostream* os) {
// DefaultPrintTo() is overloaded. The type of its first argument // DefaultPrintTo() is overloaded. The type of its first argument
// determines which version will be picked. // determines which version will be picked.
// //
// Note that we check for recursive and other container types here, prior // Note that we check for container types here, prior to we check
// to we check for protocol message types in our operator<<. The rationale is: // for protocol message types in our operator<<. The rationale is:
// //
// For protocol messages, we want to give people a chance to // For protocol messages, we want to give people a chance to
// override Google Mock's format by defining a PrintTo() or // override Google Mock's format by defining a PrintTo() or
// operator<<. For STL containers, other formats can be // operator<<. For STL containers, other formats can be
// incompatible with Google Mock's format for the container // incompatible with Google Mock's format for the container
// elements; therefore we check for container types here to ensure // elements; therefore we check for container types here to ensure
// that our format is used. To prevent an infinite runtime recursion // that our format is used.
// during the output of recursive container types, we check first for
// those.
// //
// Note that MSVC and clang-cl do allow an implicit conversion from // Note that MSVC and clang-cl do allow an implicit conversion from
// pointer-to-function to pointer-to-object, but clang-cl warns on it. // pointer-to-function to pointer-to-object, but clang-cl warns on it.
...@@ -593,6 +627,13 @@ inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) { ...@@ -593,6 +627,13 @@ inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
} }
#endif // GTEST_HAS_STD_WSTRING #endif // GTEST_HAS_STD_WSTRING
#if GTEST_HAS_ABSL
// Overload for absl::string_view.
inline void PrintTo(absl::string_view sp, ::std::ostream* os) {
PrintTo(::std::string(sp), os);
}
#endif // GTEST_HAS_ABSL
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_ #if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
// Helper function for printing a tuple. T must be instantiated with // Helper function for printing a tuple. T must be instantiated with
// a tuple type. // a tuple type.
...@@ -722,6 +763,26 @@ class UniversalPrinter { ...@@ -722,6 +763,26 @@ class UniversalPrinter {
GTEST_DISABLE_MSC_WARNINGS_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_()
}; };
#if GTEST_HAS_ABSL
// Printer for absl::optional
template <typename T>
class UniversalPrinter<::absl::optional<T>> {
public:
static void Print(const ::absl::optional<T>& value, ::std::ostream* os) {
*os << '(';
if (!value) {
*os << "nullopt";
} else {
UniversalPrint(*value, os);
}
*os << ')';
}
};
#endif // GTEST_HAS_ABSL
// UniversalPrintArray(begin, len, os) prints an array of 'len' // UniversalPrintArray(begin, len, os) prints an array of 'len'
// elements, starting at address 'begin'. // elements, starting at address 'begin'.
template <typename T> template <typename T>
...@@ -868,7 +929,7 @@ void UniversalPrint(const T& value, ::std::ostream* os) { ...@@ -868,7 +929,7 @@ void UniversalPrint(const T& value, ::std::ostream* os) {
UniversalPrinter<T1>::Print(value, os); UniversalPrinter<T1>::Print(value, os);
} }
typedef ::std::vector<string> Strings; typedef ::std::vector< ::std::string> Strings;
// TuplePolicy<TupleT> must provide: // TuplePolicy<TupleT> must provide:
// - tuple_size // - tuple_size
...@@ -988,6 +1049,16 @@ Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) { ...@@ -988,6 +1049,16 @@ Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
} // namespace internal } // namespace internal
#if GTEST_HAS_ABSL
namespace internal2 {
template <typename T>
void TypeWithoutFormatter<T, kConvertibleToStringView>::PrintValue(
const T& value, ::std::ostream* os) {
internal::PrintTo(absl::string_view(value), os);
}
} // namespace internal2
#endif
template <typename T> template <typename T>
::std::string PrintToString(const T& value) { ::std::string PrintToString(const T& value) {
::std::stringstream ss; ::std::stringstream ss;
......
...@@ -138,7 +138,7 @@ GTEST_DECLARE_int32_(stack_trace_depth); ...@@ -138,7 +138,7 @@ GTEST_DECLARE_int32_(stack_trace_depth);
// When this flag is specified, a failed assertion will throw an // When this flag is specified, a failed assertion will throw an
// exception if exceptions are enabled, or exit the program with a // exception if exceptions are enabled, or exit the program with a
// non-zero code otherwise. // non-zero code otherwise. For use with an external test framework.
GTEST_DECLARE_bool_(throw_on_failure); GTEST_DECLARE_bool_(throw_on_failure);
// When this flag is set with a "host:port" string, on supported // When this flag is set with a "host:port" string, on supported
...@@ -1004,6 +1004,18 @@ class Environment { ...@@ -1004,6 +1004,18 @@ class Environment {
virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; } virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
}; };
#if GTEST_HAS_EXCEPTIONS
// Exception which can be thrown from TestEventListener::OnTestPartResult.
class GTEST_API_ AssertionException
: public internal::GoogleTestFailureException {
public:
explicit AssertionException(const TestPartResult& result)
: GoogleTestFailureException(result) {}
};
#endif // GTEST_HAS_EXCEPTIONS
// The interface for tracing execution of tests. The methods are organized in // The interface for tracing execution of tests. The methods are organized in
// the order the corresponding events are fired. // the order the corresponding events are fired.
class TestEventListener { class TestEventListener {
...@@ -1032,6 +1044,8 @@ class TestEventListener { ...@@ -1032,6 +1044,8 @@ class TestEventListener {
virtual void OnTestStart(const TestInfo& test_info) = 0; virtual void OnTestStart(const TestInfo& test_info) = 0;
// Fired after a failed assertion or a SUCCEED() invocation. // Fired after a failed assertion or a SUCCEED() invocation.
// If you want to throw an exception from this function to skip to the next
// TEST, it must be AssertionException defined above, or inherited from it.
virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0; virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
// Fired after the test ends. // Fired after the test ends.
......
...@@ -40,17 +40,20 @@ ...@@ -40,17 +40,20 @@
// //
// class MyClass { // class MyClass {
// private: // private:
// void MyMethod(); // void PrivateMethod();
// FRIEND_TEST(MyClassTest, MyMethod); // FRIEND_TEST(MyClassTest, PrivateMethodWorks);
// }; // };
// //
// class MyClassTest : public testing::Test { // class MyClassTest : public testing::Test {
// // ... // // ...
// }; // };
// //
// TEST_F(MyClassTest, MyMethod) { // TEST_F(MyClassTest, PrivateMethodWorks) {
// // Can call MyClass::MyMethod() here. // // Can call MyClass::PrivateMethod() here.
// } // }
//
// Note: The test class must be in the same namespace as the class being tested.
// For example, putting MyClassTest in an anonymous namespace will not work.
#define FRIEND_TEST(test_case_name, test_name)\ #define FRIEND_TEST(test_case_name, test_name)\
friend class test_case_name##_##test_name##_Test friend class test_case_name##_##test_name##_Test
......
...@@ -803,31 +803,6 @@ struct RemoveConst<T[N]> { ...@@ -803,31 +803,6 @@ struct RemoveConst<T[N]> {
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \ #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T)) GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
// Adds reference to a type if it is not a reference type,
// otherwise leaves it unchanged. This is the same as
// tr1::add_reference, which is not widely available yet.
template <typename T>
struct AddReference { typedef T& type; }; // NOLINT
template <typename T>
struct AddReference<T&> { typedef T& type; }; // NOLINT
// A handy wrapper around AddReference that works when the argument T
// depends on template parameters.
#define GTEST_ADD_REFERENCE_(T) \
typename ::testing::internal::AddReference<T>::type
// Adds a reference to const on top of T as necessary. For example,
// it transforms
//
// char ==> const char&
// const char ==> const char&
// char& ==> const char&
// const char& ==> const char&
//
// The argument T must depend on some template parameters.
#define GTEST_REFERENCE_TO_CONST_(T) \
GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T))
// ImplicitlyConvertible<From, To>::value is a compile-time bool // ImplicitlyConvertible<From, To>::value is a compile-time bool
// constant that's true iff type From can be implicitly converted to // constant that's true iff type From can be implicitly converted to
// type To. // type To.
...@@ -1075,7 +1050,7 @@ class NativeArray { ...@@ -1075,7 +1050,7 @@ class NativeArray {
private: private:
enum { enum {
kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper< kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper<
Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value, Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value
}; };
// Initializes this object with a copy of the input. // Initializes this object with a copy of the input.
......
...@@ -73,11 +73,9 @@ ...@@ -73,11 +73,9 @@
// GTEST_HAS_EXCEPTIONS - Define it to 1/0 to indicate that exceptions // GTEST_HAS_EXCEPTIONS - Define it to 1/0 to indicate that exceptions
// are enabled. // are enabled.
// GTEST_HAS_GLOBAL_STRING - Define it to 1/0 to indicate that ::string // GTEST_HAS_GLOBAL_STRING - Define it to 1/0 to indicate that ::string
// is/isn't available (some systems define // is/isn't available
// ::string, which is different to std::string). // GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::wstring
// GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string // is/isn't available
// is/isn't available (some systems define
// ::wstring, which is different to std::wstring).
// GTEST_HAS_POSIX_RE - Define it to 1/0 to indicate that POSIX regular // GTEST_HAS_POSIX_RE - Define it to 1/0 to indicate that POSIX regular
// expressions are/aren't available. // expressions are/aren't available.
// GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread.h> // GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread.h>
...@@ -178,7 +176,7 @@ ...@@ -178,7 +176,7 @@
// GTEST_HAS_POSIX_RE (see above) which users can // GTEST_HAS_POSIX_RE (see above) which users can
// define themselves. // define themselves.
// GTEST_USES_SIMPLE_RE - our own simple regex is used; // GTEST_USES_SIMPLE_RE - our own simple regex is used;
// the above two are mutually exclusive. // the above RE\b(s) are mutually exclusive.
// GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ(). // GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
// Misc public macros // Misc public macros
...@@ -207,6 +205,7 @@ ...@@ -207,6 +205,7 @@
// //
// C++11 feature wrappers: // C++11 feature wrappers:
// //
// testing::internal::forward - portability wrapper for std::forward.
// testing::internal::move - portability wrapper for std::move. // testing::internal::move - portability wrapper for std::move.
// //
// Synchronization: // Synchronization:
...@@ -272,10 +271,12 @@ ...@@ -272,10 +271,12 @@
# include <TargetConditionals.h> # include <TargetConditionals.h>
#endif #endif
// Brings in the definition of HAS_GLOBAL_STRING. This must be done
// BEFORE we test HAS_GLOBAL_STRING.
#include <string> // NOLINT
#include <algorithm> // NOLINT #include <algorithm> // NOLINT
#include <iostream> // NOLINT #include <iostream> // NOLINT
#include <sstream> // NOLINT #include <sstream> // NOLINT
#include <string> // NOLINT
#include <utility> #include <utility>
#include <vector> // NOLINT #include <vector> // NOLINT
...@@ -827,9 +828,10 @@ using ::std::tuple_size; ...@@ -827,9 +828,10 @@ using ::std::tuple_size;
# define GTEST_HAS_TYPED_TEST_P 1 # define GTEST_HAS_TYPED_TEST_P 1
#endif #endif
// Determines whether to support Combine(). // Determines whether to support Combine(). This only makes sense when
// The implementation doesn't work on Sun Studio since it doesn't // value-parameterized tests are enabled. The implementation doesn't
// understand templated conversion operators. // work on Sun Studio since it doesn't understand templated conversion
// operators.
#if (GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_) && !defined(__SUNPRO_CC) #if (GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_) && !defined(__SUNPRO_CC)
# define GTEST_HAS_COMBINE 1 # define GTEST_HAS_COMBINE 1
#endif #endif
...@@ -1129,6 +1131,16 @@ struct StaticAssertTypeEqHelper<T, T> { ...@@ -1129,6 +1131,16 @@ struct StaticAssertTypeEqHelper<T, T> {
enum { value = true }; enum { value = true };
}; };
// Same as std::is_same<>.
template <typename T, typename U>
struct IsSame {
enum { value = false };
};
template <typename T>
struct IsSame<T, T> {
enum { value = true };
};
// Evaluates to the number of elements in 'array'. // Evaluates to the number of elements in 'array'.
#define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0])) #define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0]))
...@@ -1192,6 +1204,10 @@ class scoped_ptr { ...@@ -1192,6 +1204,10 @@ class scoped_ptr {
// Defines RE. // Defines RE.
#if GTEST_USES_PCRE
using ::RE;
#elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE
// A simple C++ wrapper for <regex.h>. It uses the POSIX Extended // A simple C++ wrapper for <regex.h>. It uses the POSIX Extended
// Regular Expression syntax. // Regular Expression syntax.
class GTEST_API_ RE { class GTEST_API_ RE {
...@@ -1203,11 +1219,11 @@ class GTEST_API_ RE { ...@@ -1203,11 +1219,11 @@ class GTEST_API_ RE {
// Constructs an RE from a string. // Constructs an RE from a string.
RE(const ::std::string& regex) { Init(regex.c_str()); } // NOLINT RE(const ::std::string& regex) { Init(regex.c_str()); } // NOLINT
#if GTEST_HAS_GLOBAL_STRING # if GTEST_HAS_GLOBAL_STRING
RE(const ::string& regex) { Init(regex.c_str()); } // NOLINT RE(const ::string& regex) { Init(regex.c_str()); } // NOLINT
#endif // GTEST_HAS_GLOBAL_STRING # endif // GTEST_HAS_GLOBAL_STRING
RE(const char* regex) { Init(regex); } // NOLINT RE(const char* regex) { Init(regex); } // NOLINT
~RE(); ~RE();
...@@ -1229,7 +1245,7 @@ class GTEST_API_ RE { ...@@ -1229,7 +1245,7 @@ class GTEST_API_ RE {
return PartialMatch(str.c_str(), re); return PartialMatch(str.c_str(), re);
} }
#if GTEST_HAS_GLOBAL_STRING # if GTEST_HAS_GLOBAL_STRING
static bool FullMatch(const ::string& str, const RE& re) { static bool FullMatch(const ::string& str, const RE& re) {
return FullMatch(str.c_str(), re); return FullMatch(str.c_str(), re);
...@@ -1238,7 +1254,7 @@ class GTEST_API_ RE { ...@@ -1238,7 +1254,7 @@ class GTEST_API_ RE {
return PartialMatch(str.c_str(), re); return PartialMatch(str.c_str(), re);
} }
#endif // GTEST_HAS_GLOBAL_STRING # endif // GTEST_HAS_GLOBAL_STRING
static bool FullMatch(const char* str, const RE& re); static bool FullMatch(const char* str, const RE& re);
static bool PartialMatch(const char* str, const RE& re); static bool PartialMatch(const char* str, const RE& re);
...@@ -1252,20 +1268,22 @@ class GTEST_API_ RE { ...@@ -1252,20 +1268,22 @@ class GTEST_API_ RE {
const char* pattern_; const char* pattern_;
bool is_valid_; bool is_valid_;
#if GTEST_USES_POSIX_RE # if GTEST_USES_POSIX_RE
regex_t full_regex_; // For FullMatch(). regex_t full_regex_; // For FullMatch().
regex_t partial_regex_; // For PartialMatch(). regex_t partial_regex_; // For PartialMatch().
#else // GTEST_USES_SIMPLE_RE # else // GTEST_USES_SIMPLE_RE
const char* full_pattern_; // For FullMatch(); const char* full_pattern_; // For FullMatch();
#endif # endif
GTEST_DISALLOW_ASSIGN_(RE); GTEST_DISALLOW_ASSIGN_(RE);
}; };
#endif // GTEST_USES_PCRE
// Formats a source file path and a line number as they would appear // Formats a source file path and a line number as they would appear
// in an error message from the compiler used to compile this code. // in an error message from the compiler used to compile this code.
GTEST_API_ ::std::string FormatFileLocation(const char* file, int line); GTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
...@@ -1351,13 +1369,57 @@ inline void FlushInfoLog() { fflush(NULL); } ...@@ -1351,13 +1369,57 @@ inline void FlushInfoLog() { fflush(NULL); }
GTEST_LOG_(FATAL) << #posix_call << "failed with error " \ GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
<< gtest_error << gtest_error
// Adds reference to a type if it is not a reference type,
// otherwise leaves it unchanged. This is the same as
// tr1::add_reference, which is not widely available yet.
template <typename T>
struct AddReference { typedef T& type; }; // NOLINT
template <typename T>
struct AddReference<T&> { typedef T& type; }; // NOLINT
// A handy wrapper around AddReference that works when the argument T
// depends on template parameters.
#define GTEST_ADD_REFERENCE_(T) \
typename ::testing::internal::AddReference<T>::type
// Transforms "T" into "const T&" according to standard reference collapsing
// rules (this is only needed as a backport for C++98 compilers that do not
// support reference collapsing). Specifically, it transforms:
//
// char ==> const char&
// const char ==> const char&
// char& ==> char&
// const char& ==> const char&
//
// Note that the non-const reference will not have "const" added. This is
// standard, and necessary so that "T" can always bind to "const T&".
template <typename T>
struct ConstRef { typedef const T& type; };
template <typename T>
struct ConstRef<T&> { typedef T& type; };
// The argument T must depend on some template parameters.
#define GTEST_REFERENCE_TO_CONST_(T) \
typename ::testing::internal::ConstRef<T>::type
#if GTEST_HAS_STD_MOVE_ #if GTEST_HAS_STD_MOVE_
using std::forward;
using std::move; using std::move;
template <typename T>
struct RvalueRef {
typedef T&& type;
};
#else // GTEST_HAS_STD_MOVE_ #else // GTEST_HAS_STD_MOVE_
template <typename T> template <typename T>
const T& move(const T& t) { const T& move(const T& t) {
return t; return t;
} }
template <typename T>
struct RvalueRef {
typedef const T& type;
};
#endif // GTEST_HAS_STD_MOVE_ #endif // GTEST_HAS_STD_MOVE_
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
...@@ -1458,7 +1520,6 @@ GTEST_API_ void CaptureStderr(); ...@@ -1458,7 +1520,6 @@ GTEST_API_ void CaptureStderr();
GTEST_API_ std::string GetCapturedStderr(); GTEST_API_ std::string GetCapturedStderr();
#endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION
// Returns the size (in bytes) of a file. // Returns the size (in bytes) of a file.
GTEST_API_ size_t GetFileSize(FILE* file); GTEST_API_ size_t GetFileSize(FILE* file);
......
...@@ -73,7 +73,7 @@ namespace testing { ...@@ -73,7 +73,7 @@ namespace testing {
// Constants. // Constants.
// The default death test style. // The default death test style.
static const char kDefaultDeathTestStyle[] = "fast"; static const char kDefaultDeathTestStyle[] = "threadsafe";
GTEST_DEFINE_string_( GTEST_DEFINE_string_(
death_test_style, death_test_style,
...@@ -555,7 +555,13 @@ bool DeathTestImpl::Passed(bool status_ok) { ...@@ -555,7 +555,13 @@ bool DeathTestImpl::Passed(bool status_ok) {
break; break;
case DIED: case DIED:
if (status_ok) { if (status_ok) {
# if GTEST_USES_PCRE
// PCRE regexes support embedded NULs.
// GTEST_USES_PCRE is defined only in google3 mode
const bool matched = RE::PartialMatch(error_message, *regex());
# else
const bool matched = RE::PartialMatch(error_message.c_str(), *regex()); const bool matched = RE::PartialMatch(error_message.c_str(), *regex());
# endif // GTEST_USES_PCRE
if (matched) { if (matched) {
success = true; success = true;
} else { } else {
......
...@@ -128,7 +128,7 @@ FilePath FilePath::RemoveExtension(const char* extension) const { ...@@ -128,7 +128,7 @@ FilePath FilePath::RemoveExtension(const char* extension) const {
return *this; return *this;
} }
// Returns a pointer to the last occurence of a valid path separator in // Returns a pointer to the last occurrence of a valid path separator in
// the FilePath. On Windows, for example, both '/' and '\' are valid path // the FilePath. On Windows, for example, both '/' and '\' are valid path
// separators. Returns NULL if no path separator was found. // separators. Returns NULL if no path separator was found.
const char* FilePath::FindLastPathSeparator() const { const char* FilePath::FindLastPathSeparator() const {
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
# include <windows.h> // NOLINT # include <windows.h> // NOLINT
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#include "gtest/gtest.h" // NOLINT #include "gtest/gtest.h"
#include "gtest/gtest-spi.h" #include "gtest/gtest-spi.h"
namespace testing { namespace testing {
...@@ -1024,7 +1024,7 @@ class TestResultAccessor { ...@@ -1024,7 +1024,7 @@ class TestResultAccessor {
#if GTEST_CAN_STREAM_RESULTS_ #if GTEST_CAN_STREAM_RESULTS_
// Streams test results to the given port on the given host machine. // Streams test results to the given port on the given host machine.
class GTEST_API_ StreamingListener : public EmptyTestEventListener { class StreamingListener : public EmptyTestEventListener {
public: public:
// Abstract base class for writing strings to a socket. // Abstract base class for writing strings to a socket.
class AbstractSocketWriter { class AbstractSocketWriter {
......
...@@ -915,6 +915,7 @@ GTestLog::~GTestLog() { ...@@ -915,6 +915,7 @@ GTestLog::~GTestLog() {
posix::Abort(); posix::Abort();
} }
} }
// Disable Microsoft deprecation warnings for POSIX functions called from // Disable Microsoft deprecation warnings for POSIX functions called from
// this class (creat, dup, dup2, and close) // this class (creat, dup, dup2, and close)
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996)
...@@ -1007,8 +1008,7 @@ static CapturedStream* g_captured_stderr = NULL; ...@@ -1007,8 +1008,7 @@ static CapturedStream* g_captured_stderr = NULL;
static CapturedStream* g_captured_stdout = NULL; static CapturedStream* g_captured_stdout = NULL;
// Starts capturing an output stream (stdout/stderr). // Starts capturing an output stream (stdout/stderr).
static void CaptureStream(int fd, static void CaptureStream(int fd, const char* stream_name,
const char* stream_name,
CapturedStream** stream) { CapturedStream** stream) {
if (*stream != NULL) { if (*stream != NULL) {
GTEST_LOG_(FATAL) << "Only one " << stream_name GTEST_LOG_(FATAL) << "Only one " << stream_name
...@@ -1049,6 +1049,10 @@ std::string GetCapturedStderr() { ...@@ -1049,6 +1049,10 @@ std::string GetCapturedStderr() {
#endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION
size_t GetFileSize(FILE* file) { size_t GetFileSize(FILE* file) {
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
return static_cast<size_t>(ftell(file)); return static_cast<size_t>(ftell(file));
......
...@@ -124,7 +124,7 @@ namespace internal { ...@@ -124,7 +124,7 @@ namespace internal {
// Depending on the value of a char (or wchar_t), we print it in one // Depending on the value of a char (or wchar_t), we print it in one
// of three formats: // of three formats:
// - as is if it's a printable ASCII (e.g. 'a', '2', ' '), // - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
// - as a hexidecimal escape sequence (e.g. '\x7F'), or // - as a hexadecimal escape sequence (e.g. '\x7F'), or
// - as a special escape sequence (e.g. '\r', '\n'). // - as a special escape sequence (e.g. '\r', '\n').
enum CharFormat { enum CharFormat {
kAsIs, kAsIs,
...@@ -231,7 +231,7 @@ void PrintCharAndCodeTo(Char c, ostream* os) { ...@@ -231,7 +231,7 @@ void PrintCharAndCodeTo(Char c, ostream* os) {
return; return;
*os << " (" << static_cast<int>(c); *os << " (" << static_cast<int>(c);
// For more convenience, we print c's code again in hexidecimal, // For more convenience, we print c's code again in hexadecimal,
// unless c was already printed in the form '\x##' or the code is in // unless c was already printed in the form '\x##' or the code is in
// [1, 9]. // [1, 9].
if (format == kHexEscape || (1 <= c && c <= 9)) { if (format == kHexEscape || (1 <= c && c <= 9)) {
...@@ -357,8 +357,10 @@ void PrintTo(const wchar_t* s, ostream* os) { ...@@ -357,8 +357,10 @@ void PrintTo(const wchar_t* s, ostream* os) {
namespace { namespace {
bool ContainsUnprintableControlCodes(const char* str, size_t length) { bool ContainsUnprintableControlCodes(const char* str, size_t length) {
const unsigned char *s = reinterpret_cast<const unsigned char *>(str);
for (size_t i = 0; i < length; i++) { for (size_t i = 0; i < length; i++) {
char ch = *str++; unsigned char ch = *s++;
if (std::iscntrl(ch)) { if (std::iscntrl(ch)) {
switch (ch) { switch (ch) {
case '\t': case '\t':
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
// Author: wan@google.com (Zhanyong Wan) // Author: wan@google.com (Zhanyong Wan)
#include "gtest/gtest-typed-test.h" #include "gtest/gtest-typed-test.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace testing { namespace testing {
......
...@@ -293,7 +293,7 @@ GTEST_DEFINE_bool_( ...@@ -293,7 +293,7 @@ GTEST_DEFINE_bool_(
internal::BoolFromGTestEnv("throw_on_failure", false), internal::BoolFromGTestEnv("throw_on_failure", false),
"When this flag is specified, a failed assertion will throw an exception " "When this flag is specified, a failed assertion will throw an exception "
"if exceptions are enabled or exit the program with a non-zero code " "if exceptions are enabled or exit the program with a non-zero code "
"otherwise."); "otherwise. For use with an external test framework.");
#if GTEST_USE_OWN_FLAGFILE_FLAG_ #if GTEST_USE_OWN_FLAGFILE_FLAG_
GTEST_DEFINE_string_( GTEST_DEFINE_string_(
...@@ -1718,7 +1718,7 @@ AssertionResult IsHRESULTFailure(const char* expr, long hr) { // NOLINT ...@@ -1718,7 +1718,7 @@ AssertionResult IsHRESULTFailure(const char* expr, long hr) { // NOLINT
// Utility functions for encoding Unicode text (wide strings) in // Utility functions for encoding Unicode text (wide strings) in
// UTF-8. // UTF-8.
// A Unicode code-point can have upto 21 bits, and is encoded in UTF-8 // A Unicode code-point can have up to 21 bits, and is encoded in UTF-8
// like this: // like this:
// //
// Code-point length Encoding // Code-point length Encoding
...@@ -2435,6 +2435,8 @@ Result HandleExceptionsInMethodIfSupported( ...@@ -2435,6 +2435,8 @@ Result HandleExceptionsInMethodIfSupported(
#if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
try { try {
return HandleSehExceptionsInMethodIfSupported(object, method, location); return HandleSehExceptionsInMethodIfSupported(object, method, location);
} catch (const AssertionException&) { // NOLINT
// This failure was reported already.
} catch (const internal::GoogleTestFailureException&) { // NOLINT } catch (const internal::GoogleTestFailureException&) { // NOLINT
// This exception type can only be thrown by a failed Google // This exception type can only be thrown by a failed Google
// Test assertion with the intention of letting another testing // Test assertion with the intention of letting another testing
...@@ -2569,12 +2571,10 @@ void ReportInvalidTestCaseType(const char* test_case_name, ...@@ -2569,12 +2571,10 @@ void ReportInvalidTestCaseType(const char* test_case_name,
<< "probably rename one of the classes to put the tests into different\n" << "probably rename one of the classes to put the tests into different\n"
<< "test cases."; << "test cases.";
GTEST_LOG_(ERROR) GTEST_LOG_(ERROR) << FormatFileLocation(code_location.file.c_str(),
<< FormatFileLocation(code_location.file.c_str(),
code_location.line) code_location.line)
<< " " << errors.GetString(); << " " << errors.GetString();
} }
} // namespace internal } // namespace internal
namespace { namespace {
...@@ -2896,7 +2896,7 @@ static int GetBitOffset(WORD color_mask) { ...@@ -2896,7 +2896,7 @@ static int GetBitOffset(WORD color_mask) {
if (color_mask == 0) return 0; if (color_mask == 0) return 0;
int bitOffset = 0; int bitOffset = 0;
while((color_mask & 1) == 0) { while ((color_mask & 1) == 0) {
color_mask >>= 1; color_mask >>= 1;
++bitOffset; ++bitOffset;
} }
...@@ -3104,7 +3104,6 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart( ...@@ -3104,7 +3104,6 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart(
"Note: Randomizing tests' orders with a seed of %d .\n", "Note: Randomizing tests' orders with a seed of %d .\n",
unit_test.random_seed()); unit_test.random_seed());
} }
ColoredPrintf(COLOR_GREEN, "[==========] "); ColoredPrintf(COLOR_GREEN, "[==========] ");
printf("Running %s from %s.\n", printf("Running %s from %s.\n",
FormatTestCount(unit_test.test_to_run_count()).c_str(), FormatTestCount(unit_test.test_to_run_count()).c_str(),
...@@ -3471,8 +3470,8 @@ void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, ...@@ -3471,8 +3470,8 @@ void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
// 3. To interpret the meaning of errno in a thread-safe way, // 3. To interpret the meaning of errno in a thread-safe way,
// we need the strerror_r() function, which is not available on // we need the strerror_r() function, which is not available on
// Windows. // Windows.
GTEST_LOG_(FATAL) << "Unable to open file \""
<< output_file_ << "\""; GTEST_LOG_(FATAL) << "Unable to open file \"" << output_file_ << "\"";
} }
std::stringstream stream; std::stringstream stream;
PrintXmlUnitTest(&stream, unit_test); PrintXmlUnitTest(&stream, unit_test);
...@@ -3771,6 +3770,7 @@ std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes( ...@@ -3771,6 +3770,7 @@ std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(
// End XmlUnitTestResultPrinter // End XmlUnitTestResultPrinter
#if GTEST_CAN_STREAM_RESULTS_ #if GTEST_CAN_STREAM_RESULTS_
// Checks if str contains '=', '&', '%' or '\n' characters. If yes, // Checks if str contains '=', '&', '%' or '\n' characters. If yes,
...@@ -4399,8 +4399,7 @@ void UnitTestImpl::ConfigureXmlOutput() { ...@@ -4399,8 +4399,7 @@ void UnitTestImpl::ConfigureXmlOutput() {
UnitTestOptions::GetAbsolutePathToOutputFile().c_str())); UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
} else if (output_format != "") { } else if (output_format != "") {
GTEST_LOG_(WARNING) << "WARNING: unrecognized output format \"" GTEST_LOG_(WARNING) << "WARNING: unrecognized output format \""
<< output_format << output_format << "\" ignored.";
<< "\" ignored.";
} }
} }
...@@ -4415,8 +4414,7 @@ void UnitTestImpl::ConfigureStreamingOutput() { ...@@ -4415,8 +4414,7 @@ void UnitTestImpl::ConfigureStreamingOutput() {
listeners()->Append(new StreamingListener(target.substr(0, pos), listeners()->Append(new StreamingListener(target.substr(0, pos),
target.substr(pos+1))); target.substr(pos+1)));
} else { } else {
GTEST_LOG_(WARNING) << "unrecognized streaming target \"" GTEST_LOG_(WARNING) << "unrecognized streaming target \"" << target
<< target
<< "\" ignored."; << "\" ignored.";
} }
} }
...@@ -5201,7 +5199,8 @@ static const char kColorEncodedHelpMessage[] = ...@@ -5201,7 +5199,8 @@ static const char kColorEncodedHelpMessage[] =
" @G--" GTEST_FLAG_PREFIX_ "break_on_failure@D\n" " @G--" GTEST_FLAG_PREFIX_ "break_on_failure@D\n"
" Turn assertion failures into debugger break-points.\n" " Turn assertion failures into debugger break-points.\n"
" @G--" GTEST_FLAG_PREFIX_ "throw_on_failure@D\n" " @G--" GTEST_FLAG_PREFIX_ "throw_on_failure@D\n"
" Turn assertion failures into C++ exceptions.\n" " Turn assertion failures into C++ exceptions for use by an external\n"
" test framework.\n"
" @G--" GTEST_FLAG_PREFIX_ "catch_exceptions=0@D\n" " @G--" GTEST_FLAG_PREFIX_ "catch_exceptions=0@D\n"
" Do not report exceptions as test failures. Instead, allow them\n" " Do not report exceptions as test failures. Instead, allow them\n"
" to crash the program or throw a pop-up (on Windows).\n" " to crash the program or throw a pop-up (on Windows).\n"
...@@ -5252,8 +5251,7 @@ static bool ParseGoogleTestFlag(const char* const arg) { ...@@ -5252,8 +5251,7 @@ static bool ParseGoogleTestFlag(const char* const arg) {
static void LoadFlagsFromFile(const std::string& path) { static void LoadFlagsFromFile(const std::string& path) {
FILE* flagfile = posix::FOpen(path.c_str(), "r"); FILE* flagfile = posix::FOpen(path.c_str(), "r");
if (!flagfile) { if (!flagfile) {
GTEST_LOG_(FATAL) << "Unable to open file \"" GTEST_LOG_(FATAL) << "Unable to open file \"" << GTEST_FLAG(flagfile)
<< GTEST_FLAG(flagfile)
<< "\""; << "\"";
} }
std::string contents(ReadEntireFile(flagfile)); std::string contents(ReadEntireFile(flagfile));
...@@ -5386,6 +5384,7 @@ std::string TempDir() { ...@@ -5386,6 +5384,7 @@ std::string TempDir() {
#if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_) #if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_)
return GTEST_CUSTOM_TEMPDIR_FUNCTION_(); return GTEST_CUSTOM_TEMPDIR_FUNCTION_();
#endif #endif
#if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
return "\\temp\\"; return "\\temp\\";
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
......
...@@ -119,6 +119,16 @@ cc_test( ...@@ -119,6 +119,16 @@ cc_test(
"//:gtest", "//:gtest",
], ],
) )
cc_test(
name = "gtest_unittest",
size = "small",
srcs = ["gtest_unittest.cc"],
args = ["--heap_check=strict"],
shard_count = 2,
deps = ["//:gtest_main"],
)
# Py tests # Py tests
py_library( py_library(
...@@ -219,6 +229,13 @@ py_test( ...@@ -219,6 +229,13 @@ py_test(
deps = [":gtest_test_utils"], deps = [":gtest_test_utils"],
) )
cc_test(
name = "gtest_assert_by_exception_test",
size = "small",
srcs = ["gtest_assert_by_exception_test.cc"],
deps = ["//:gtest"],
)
cc_binary( cc_binary(
name = "gtest_throw_on_failure_test_", name = "gtest_throw_on_failure_test_",
testonly = 1, testonly = 1,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment