Merge branch 'master' into deprecate

This commit is contained in:
Loo Rong Jie 2018-08-09 20:08:44 +08:00 committed by GitHub
commit 24786cb498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 117 additions and 72 deletions

View File

@ -37,7 +37,8 @@
// causes a link error when _tmain is defined in a static library and UNICODE // causes a link error when _tmain is defined in a static library and UNICODE
// is enabled. For this reason instead of _tmain, main function is used on // is enabled. For this reason instead of _tmain, main function is used on
// Windows. See the following link to track the current status of this bug: // Windows. See the following link to track the current status of this bug:
// https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library // NOLINT // https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library
// // NOLINT
#if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
# include <tchar.h> // NOLINT # include <tchar.h> // NOLINT

View File

@ -100,6 +100,7 @@ GTEST_API_ bool InDeathTestChild();
// //
// On the regular expressions used in death tests: // On the regular expressions used in death tests:
// //
// GOOGLETEST_CM0005 DO NOT DELETE
// On POSIX-compliant systems (*nix), we use the <regex.h> library, // On POSIX-compliant systems (*nix), we use the <regex.h> library,
// which uses the POSIX extended regex syntax. // which uses the POSIX extended regex syntax.
// //
@ -202,6 +203,7 @@ class GTEST_API_ ExitedWithCode {
# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA # if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
// Tests that an exit code describes an exit due to termination by a // Tests that an exit code describes an exit due to termination by a
// given signal. // given signal.
// GOOGLETEST_CM0006 DO NOT DELETE
class GTEST_API_ KilledBySignal { class GTEST_API_ KilledBySignal {
public: public:
explicit KilledBySignal(int signum); explicit KilledBySignal(int signum);

View File

@ -397,7 +397,8 @@
#if GTEST_LANG_CXX11 #if GTEST_LANG_CXX11
# define GTEST_HAS_STD_TUPLE_ 1 # define GTEST_HAS_STD_TUPLE_ 1
# if defined(__clang__) # if defined(__clang__)
// Inspired by https://clang.llvm.org/docs/LanguageExtensions.html#include-file-checking-macros // Inspired by
// https://clang.llvm.org/docs/LanguageExtensions.html#include-file-checking-macros
# if defined(__has_include) && !__has_include(<tuple>) # if defined(__has_include) && !__has_include(<tuple>)
# undef GTEST_HAS_STD_TUPLE_ # undef GTEST_HAS_STD_TUPLE_
# endif # endif

View File

@ -67,6 +67,7 @@
# include <lib/fdio/spawn.h> # include <lib/fdio/spawn.h>
# include <zircon/processargs.h> # include <zircon/processargs.h>
# include <zircon/syscalls.h> # include <zircon/syscalls.h>
# include <zircon/syscalls/port.h>
# endif // GTEST_OS_FUCHSIA # endif // GTEST_OS_FUCHSIA
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
@ -236,6 +237,9 @@ static std::string DeathTestThreadWarning(size_t thread_count) {
msg << "couldn't detect the number of threads."; msg << "couldn't detect the number of threads.";
else else
msg << "detected " << thread_count << " threads."; msg << "detected " << thread_count << " threads.";
msg << " See https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#death-tests-and-threads"
<< " for more explanation and suggested solutions, especially if"
<< " this is the last message you see before your test times out.";
return msg.GetString(); return msg.GetString();
} }
# endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA # endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
@ -805,6 +809,12 @@ class FuchsiaDeathTest : public DeathTestImpl {
const char* file, const char* file,
int line) int line)
: DeathTestImpl(a_statement, a_regex), file_(file), line_(line) {} : DeathTestImpl(a_statement, a_regex), file_(file), line_(line) {}
virtual ~FuchsiaDeathTest() {
zx_status_t status = zx_handle_close(child_process_);
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
status = zx_handle_close(port_);
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
}
// All of these virtual functions are inherited from DeathTest. // All of these virtual functions are inherited from DeathTest.
virtual int Wait(); virtual int Wait();
@ -816,7 +826,8 @@ class FuchsiaDeathTest : public DeathTestImpl {
// The line number on which the death test is located. // The line number on which the death test is located.
const int line_; const int line_;
zx_handle_t child_process_; zx_handle_t child_process_ = ZX_HANDLE_INVALID;
zx_handle_t port_ = ZX_HANDLE_INVALID;
}; };
// Utility class for accumulating command-line arguments. // Utility class for accumulating command-line arguments.
@ -863,16 +874,38 @@ int FuchsiaDeathTest::Wait() {
if (!spawned()) if (!spawned())
return 0; return 0;
// Wait for child process to terminate. // Register to wait for the child process to terminate.
zx_status_t status_zx; zx_status_t status_zx;
zx_signals_t signals; status_zx = zx_object_wait_async(child_process_,
status_zx = zx_object_wait_one( port_,
child_process_, 0 /* key */,
ZX_PROCESS_TERMINATED, ZX_PROCESS_TERMINATED,
ZX_TIME_INFINITE, ZX_WAIT_ASYNC_ONCE);
&signals);
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK); GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
// Wait for it to terminate, or an exception to be received.
zx_port_packet_t packet;
status_zx = zx_port_wait(port_, ZX_TIME_INFINITE, &packet);
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
if (ZX_PKT_IS_EXCEPTION(packet.type)) {
// Process encountered an exception. Kill it directly rather than letting
// other handlers process the event.
status_zx = zx_task_kill(child_process_);
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
// Now wait for |child_process_| to terminate.
zx_signals_t signals = 0;
status_zx = zx_object_wait_one(
child_process_, ZX_PROCESS_TERMINATED, ZX_TIME_INFINITE, &signals);
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
GTEST_DEATH_TEST_CHECK_(signals & ZX_PROCESS_TERMINATED);
} else {
// Process terminated.
GTEST_DEATH_TEST_CHECK_(ZX_PKT_IS_SIGNAL_ONE(packet.type));
GTEST_DEATH_TEST_CHECK_(packet.signal.observed & ZX_PROCESS_TERMINATED);
}
ReadAndInterpretStatusByte(); ReadAndInterpretStatusByte();
zx_info_process_t buffer; zx_info_process_t buffer;
@ -936,13 +969,10 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
set_read_fd(status); set_read_fd(status);
// Set the pipe handle for the child. // Set the pipe handle for the child.
fdio_spawn_action_t add_handle_action = { fdio_spawn_action_t add_handle_action = {};
.action = FDIO_SPAWN_ACTION_ADD_HANDLE, add_handle_action.action = FDIO_SPAWN_ACTION_ADD_HANDLE;
.h = { add_handle_action.h.id = PA_HND(type, kFuchsiaReadPipeFd);
.id = PA_HND(type, kFuchsiaReadPipeFd), add_handle_action.h.handle = child_pipe_handle;
.handle = child_pipe_handle
}
};
// Spawn the child process. // Spawn the child process.
status = fdio_spawn_etc(ZX_HANDLE_INVALID, FDIO_SPAWN_CLONE_ALL, status = fdio_spawn_etc(ZX_HANDLE_INVALID, FDIO_SPAWN_CLONE_ALL,
@ -950,6 +980,14 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
&add_handle_action, &child_process_, nullptr); &add_handle_action, &child_process_, nullptr);
GTEST_DEATH_TEST_CHECK_(status == ZX_OK); GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
// Create an exception port and attach it to the |child_process_|, to allow
// us to suppress the system default exception handler from firing.
status = zx_port_create(0, &port_);
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
status = zx_task_bind_exception_port(
child_process_, port_, 0 /* key */, 0 /*options */);
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
set_spawned(true); set_spawned(true);
return OVERSEE_TEST; return OVERSEE_TEST;
} }

View File

@ -3138,6 +3138,7 @@ 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(),

View File

@ -30,13 +30,14 @@
// Author: vladl@google.com (Vlad Losev) // Author: vladl@google.com (Vlad Losev)
// //
// Tests for Google Test itself. Tests in this file throw C++ or SEH // Tests for Google Test itself. Tests in this file throw C++ or SEH
// exceptions, and the output is verified by googletest-catch-exceptions-test.py. // exceptions, and the output is verified by
// googletest-catch-exceptions-test.py.
#include "gtest/gtest.h"
#include <stdio.h> // NOLINT #include <stdio.h> // NOLINT
#include <stdlib.h> // For exit(). #include <stdlib.h> // For exit().
#include "gtest/gtest.h"
#if GTEST_HAS_SEH #if GTEST_HAS_SEH
# include <windows.h> # include <windows.h>
#endif #endif

View File

@ -32,10 +32,9 @@
// A helper program for testing that Google Test parses the environment // A helper program for testing that Google Test parses the environment
// variables correctly. // variables correctly.
#include "gtest/gtest.h"
#include <iostream> #include <iostream>
#include "gtest/gtest.h"
#include "src/gtest-internal-inl.h" #include "src/gtest-internal-inl.h"
using ::std::cout; using ::std::cout;

View File

@ -30,9 +30,9 @@
// Authors: Dan Egnor (egnor@google.com) // Authors: Dan Egnor (egnor@google.com)
// Ported to Windows: Vadim Berman (vadimb@google.com) // Ported to Windows: Vadim Berman (vadimb@google.com)
#include "gtest/internal/gtest-linked_ptr.h"
#include <stdlib.h> #include <stdlib.h>
#include "gtest/internal/gtest-linked_ptr.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace { namespace {

View File

@ -33,9 +33,10 @@
// This file verifies Google Test event listeners receive events at the // This file verifies Google Test event listeners receive events at the
// right times. // right times.
#include "gtest/gtest.h"
#include <vector> #include <vector>
#include "gtest/gtest.h"
using ::testing::AddGlobalTestEnvironment; using ::testing::AddGlobalTestEnvironment;
using ::testing::Environment; using ::testing::Environment;
using ::testing::InitGoogleTest; using ::testing::InitGoogleTest;

View File

@ -32,14 +32,7 @@
__author__ = 'jmadill@google.com (Jamie Madill)' __author__ = 'jmadill@google.com (Jamie Madill)'
import os import gtest_test_utils
IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
if IS_LINUX:
import gtest_test_utils
else:
import gtest_test_utils
binary_name = 'googletest-param-test-invalid-name1-test_' binary_name = 'googletest-param-test-invalid-name1-test_'
COMMAND = gtest_test_utils.GetTestExecutablePath(binary_name) COMMAND = gtest_test_utils.GetTestExecutablePath(binary_name)

View File

@ -32,14 +32,7 @@
__author__ = 'jmadill@google.com (Jamie Madill)' __author__ = 'jmadill@google.com (Jamie Madill)'
import os import gtest_test_utils
IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
if IS_LINUX:
import gtest_test_utils
else:
import gtest_test_utils
binary_name = 'googletest-param-test-invalid-name2-test_' binary_name = 'googletest-param-test-invalid-name2-test_'
COMMAND = gtest_test_utils.GetTestExecutablePath(binary_name) COMMAND = gtest_test_utils.GetTestExecutablePath(binary_name)

View File

@ -33,7 +33,7 @@
// Google Test work. // Google Test work.
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "googletest-param-test-test.h" #include "test/googletest-param-test-test.h"
using ::testing::Values; using ::testing::Values;
using ::testing::internal::ParamGenerator; using ::testing::internal::ParamGenerator;
@ -44,17 +44,18 @@ using ::testing::internal::ParamGenerator;
ParamGenerator<int> extern_gen = Values(33); ParamGenerator<int> extern_gen = Values(33);
// Tests that a parameterized test case can be defined in one translation unit // Tests that a parameterized test case can be defined in one translation unit
// and instantiated in another. The test is defined in googletest-param-test-test.cc // and instantiated in another. The test is defined in
// and ExternalInstantiationTest fixture class is defined in // googletest-param-test-test.cc and ExternalInstantiationTest fixture class is
// gtest-param-test_test.h. // defined in gtest-param-test_test.h.
INSTANTIATE_TEST_CASE_P(MultiplesOf33, INSTANTIATE_TEST_CASE_P(MultiplesOf33,
ExternalInstantiationTest, ExternalInstantiationTest,
Values(33, 66)); Values(33, 66));
// Tests that a parameterized test case can be instantiated // Tests that a parameterized test case can be instantiated
// in multiple translation units. Another instantiation is defined // in multiple translation units. Another instantiation is defined
// in googletest-param-test-test.cc and InstantiationInMultipleTranslaionUnitsTest // in googletest-param-test-test.cc and
// fixture is defined in gtest-param-test_test.h // InstantiationInMultipleTranslaionUnitsTest fixture is defined in
// gtest-param-test_test.h
INSTANTIATE_TEST_CASE_P(Sequence2, INSTANTIATE_TEST_CASE_P(Sequence2,
InstantiationInMultipleTranslaionUnitsTest, InstantiationInMultipleTranslaionUnitsTest,
Values(42*3, 42*4, 42*5)); Values(42*3, 42*4, 42*5));

View File

@ -30,11 +30,10 @@
// Authors: vladl@google.com (Vlad Losev), wan@google.com (Zhanyong Wan) // Authors: vladl@google.com (Vlad Losev), wan@google.com (Zhanyong Wan)
// //
// This file tests the internal cross-platform support utilities. // This file tests the internal cross-platform support utilities.
#include <stdio.h>
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
#include <stdio.h>
#if GTEST_OS_MAC #if GTEST_OS_MAC
# include <time.h> # include <time.h>
#endif // GTEST_OS_MAC #endif // GTEST_OS_MAC

View File

@ -33,8 +33,6 @@
// //
// This file tests the universal value printer. // This file tests the universal value printer.
#include "gtest/gtest-printers.h"
#include <ctype.h> #include <ctype.h>
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
@ -48,6 +46,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "gtest/gtest-printers.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#if GTEST_HAS_UNORDERED_MAP_ #if GTEST_HAS_UNORDERED_MAP_
@ -572,7 +571,7 @@ struct Foo {
TEST(PrintPointerTest, MemberVariablePointer) { TEST(PrintPointerTest, MemberVariablePointer) {
EXPECT_TRUE(HasPrefix(Print(&Foo::value), EXPECT_TRUE(HasPrefix(Print(&Foo::value),
Print(sizeof(&Foo::value)) + "-byte object ")); Print(sizeof(&Foo::value)) + "-byte object "));
int (Foo::*p) = NULL; // NOLINT int Foo::*p = NULL; // NOLINT
EXPECT_TRUE(HasPrefix(Print(p), EXPECT_TRUE(HasPrefix(Print(p),
Print(sizeof(p)) + "-byte object ")); Print(sizeof(p)) + "-byte object "));
} }
@ -1250,7 +1249,7 @@ TEST(PrintReferenceTest, HandlesMemberFunctionPointer) {
// Tests that the universal printer prints a member variable pointer // Tests that the universal printer prints a member variable pointer
// passed by reference. // passed by reference.
TEST(PrintReferenceTest, HandlesMemberVariablePointer) { TEST(PrintReferenceTest, HandlesMemberVariablePointer) {
int (Foo::*p) = &Foo::value; // NOLINT int Foo::*p = &Foo::value; // NOLINT
EXPECT_TRUE(HasPrefix( EXPECT_TRUE(HasPrefix(
PrintByRef(p), PrintByRef(p),
"@" + PrintPointer(&p) + " " + Print(sizeof(p)) + "-byte object ")); "@" + PrintPointer(&p) + " " + Print(sizeof(p)) + "-byte object "));
@ -1731,6 +1730,21 @@ TEST(PrintOptionalTest, Basic) {
EXPECT_EQ("(1.1)", PrintToString(absl::optional<double>{1.1})); EXPECT_EQ("(1.1)", PrintToString(absl::optional<double>{1.1}));
EXPECT_EQ("(\"A\")", PrintToString(absl::optional<std::string>{"A"})); EXPECT_EQ("(\"A\")", PrintToString(absl::optional<std::string>{"A"}));
} }
struct NonPrintable {
unsigned char contents = 17;
};
TEST(PrintOneofTest, Basic) {
using Type = absl::variant<int, StreamableInGlobal, NonPrintable>;
EXPECT_EQ("('int' with value 7)", PrintToString(Type(7)));
EXPECT_EQ("('StreamableInGlobal' with value StreamableInGlobal)",
PrintToString(Type(StreamableInGlobal{})));
EXPECT_EQ(
"('testing::gtest_printers_test::NonPrintable' with value 1-byte object "
"<11>)",
PrintToString(Type(NonPrintable{})));
}
#endif // GTEST_HAS_ABSL #endif // GTEST_HAS_ABSL
} // namespace gtest_printers_test } // namespace gtest_printers_test

View File

@ -44,17 +44,18 @@ using ::testing::internal::ParamGenerator;
ParamGenerator<int> extern_gen_2 = Values(33); ParamGenerator<int> extern_gen_2 = Values(33);
// Tests that a parameterized test case can be defined in one translation unit // Tests that a parameterized test case can be defined in one translation unit
// and instantiated in another. The test is defined in googletest-param-test-test.cc // and instantiated in another. The test is defined in
// and ExternalInstantiationTest fixture class is defined in // googletest-param-test-test.cc and ExternalInstantiationTest fixture class is
// gtest-param-test_test.h. // defined in gtest-param-test_test.h.
INSTANTIATE_TEST_CASE_P(MultiplesOf33, INSTANTIATE_TEST_CASE_P(MultiplesOf33,
ExternalInstantiationTest, ExternalInstantiationTest,
Values(33, 66)); Values(33, 66));
// Tests that a parameterized test case can be instantiated // Tests that a parameterized test case can be instantiated
// in multiple translation units. Another instantiation is defined // in multiple translation units. Another instantiation is defined
// in googletest-param-test-test.cc and InstantiationInMultipleTranslaionUnitsTest // in googletest-param-test-test.cc and
// fixture is defined in gtest-param-test_test.h // InstantiationInMultipleTranslaionUnitsTest fixture is defined in
// gtest-param-test_test.h
INSTANTIATE_TEST_CASE_P(Sequence2, INSTANTIATE_TEST_CASE_P(Sequence2,
InstantiationInMultipleTranslaionUnitsTest, InstantiationInMultipleTranslaionUnitsTest,
Values(42*3, 42*4, 42*5)); Values(42*3, 42*4, 42*5));

View File

@ -31,7 +31,7 @@
#include <vector> #include <vector>
#include "gtest-typed-test_test.h" #include "test/gtest-typed-test_test.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#if GTEST_HAS_TYPED_TEST_P #if GTEST_HAS_TYPED_TEST_P

View File

@ -29,7 +29,7 @@
// //
// Author: wan@google.com (Zhanyong Wan) // Author: wan@google.com (Zhanyong Wan)
#include "gtest-typed-test_test.h" #include "test/gtest-typed-test_test.h"
#include <set> #include <set>
#include <vector> #include <vector>

View File

@ -33,15 +33,15 @@
// //
// Sometimes it's desirable to build most of Google Test's own tests // Sometimes it's desirable to build most of Google Test's own tests
// by compiling a single file. This file serves this purpose. // by compiling a single file. This file serves this purpose.
#include "googletest-filepath-test.cc" #include "test/googletest-filepath-test.cc"
#include "googletest-linked-ptr-test.cc" #include "test/googletest-linked-ptr-test.cc"
#include "googletest-message-test.cc" #include "test/googletest-message-test.cc"
#include "googletest-options-test.cc" #include "test/googletest-options-test.cc"
#include "googletest-port-test.cc" #include "test/googletest-port-test.cc"
#include "gtest_pred_impl_unittest.cc" #include "test/gtest_pred_impl_unittest.cc"
#include "gtest_prod_test.cc" #include "test/gtest_prod_test.cc"
#include "googletest-test-part-test.cc" #include "test/googletest-test-part-test.cc"
#include "gtest-typed-test_test.cc" #include "test/gtest-typed-test_test.cc"
#include "gtest-typed-test2_test.cc" #include "test/gtest-typed-test2_test.cc"
#include "gtest_unittest.cc" #include "test/gtest_unittest.cc"
#include "production.cc" #include "test/production.cc"