Unverified Commit 85f059f0 authored by Chris Johnson's avatar Chris Johnson Committed by GitHub
Browse files

Merge pull request #3 from google/master

Update master
parents 130e5aa8 fdd6a1dc
...@@ -89,9 +89,9 @@ if SUPPORTS_SEH_EXCEPTIONS: ...@@ -89,9 +89,9 @@ if SUPPORTS_SEH_EXCEPTIONS:
self.assert_('SEH exception with code 0x2a thrown ' self.assert_('SEH exception with code 0x2a thrown '
'in the test fixture\'s destructor' 'in the test fixture\'s destructor'
in test_output) in test_output)
self.assert_('SEH exception with code 0x2a thrown in SetUpTestCase()' self.assert_('SEH exception with code 0x2a thrown in SetUpTestSuite()'
in test_output) in test_output)
self.assert_('SEH exception with code 0x2a thrown in TearDownTestCase()' self.assert_('SEH exception with code 0x2a thrown in TearDownTestSuite()'
in test_output) in test_output)
self.assert_('SEH exception with code 0x2a thrown in SetUp()' self.assert_('SEH exception with code 0x2a thrown in SetUp()'
in test_output) in test_output)
...@@ -117,10 +117,11 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase): ...@@ -117,10 +117,11 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
""" """
def testCatchesCxxExceptionsInFixtureConstructor(self): def testCatchesCxxExceptionsInFixtureConstructor(self):
self.assert_('C++ exception with description ' self.assertTrue(
'"Standard C++ exception" thrown ' 'C++ exception with description '
'in the test fixture\'s constructor' '"Standard C++ exception" thrown '
in EX_BINARY_OUTPUT) 'in the test fixture\'s constructor' in EX_BINARY_OUTPUT,
EX_BINARY_OUTPUT)
self.assert_('unexpected' not in EX_BINARY_OUTPUT, self.assert_('unexpected' not in EX_BINARY_OUTPUT,
'This failure belongs in this test only if ' 'This failure belongs in this test only if '
'"CxxExceptionInConstructorTest" (no quotes) ' '"CxxExceptionInConstructorTest" (no quotes) '
...@@ -130,88 +131,90 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase): ...@@ -130,88 +131,90 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
EX_BINARY_OUTPUT): EX_BINARY_OUTPUT):
def testCatchesCxxExceptionsInFixtureDestructor(self): def testCatchesCxxExceptionsInFixtureDestructor(self):
self.assert_('C++ exception with description ' self.assertTrue(
'"Standard C++ exception" thrown ' 'C++ exception with description '
'in the test fixture\'s destructor' '"Standard C++ exception" thrown '
in EX_BINARY_OUTPUT) 'in the test fixture\'s destructor' in EX_BINARY_OUTPUT,
self.assert_('CxxExceptionInDestructorTest::TearDownTestCase() ' EX_BINARY_OUTPUT)
'called as expected.' self.assertTrue(
in EX_BINARY_OUTPUT) 'CxxExceptionInDestructorTest::TearDownTestSuite() '
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
def testCatchesCxxExceptionsInSetUpTestCase(self): def testCatchesCxxExceptionsInSetUpTestCase(self):
self.assert_('C++ exception with description "Standard C++ exception"' self.assertTrue(
' thrown in SetUpTestCase()' 'C++ exception with description "Standard C++ exception"'
in EX_BINARY_OUTPUT) ' thrown in SetUpTestSuite()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInConstructorTest::TearDownTestCase() ' self.assertTrue(
'called as expected.' 'CxxExceptionInConstructorTest::TearDownTestSuite() '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTestCaseTest constructor ' self.assertTrue(
'called as expected.' 'CxxExceptionInSetUpTestSuiteTest constructor '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTestCaseTest destructor ' self.assertTrue(
'called as expected.' 'CxxExceptionInSetUpTestSuiteTest destructor '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTestCaseTest::SetUp() ' self.assertTrue(
'called as expected.' 'CxxExceptionInSetUpTestSuiteTest::SetUp() '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTestCaseTest::TearDown() ' self.assertTrue(
'called as expected.' 'CxxExceptionInSetUpTestSuiteTest::TearDown() '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTestCaseTest test body ' self.assertTrue(
'called as expected.' 'CxxExceptionInSetUpTestSuiteTest test body '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
def testCatchesCxxExceptionsInTearDownTestCase(self): def testCatchesCxxExceptionsInTearDownTestCase(self):
self.assert_('C++ exception with description "Standard C++ exception"' self.assertTrue(
' thrown in TearDownTestCase()' 'C++ exception with description "Standard C++ exception"'
in EX_BINARY_OUTPUT) ' thrown in TearDownTestSuite()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
def testCatchesCxxExceptionsInSetUp(self): def testCatchesCxxExceptionsInSetUp(self):
self.assert_('C++ exception with description "Standard C++ exception"' self.assertTrue(
' thrown in SetUp()' 'C++ exception with description "Standard C++ exception"'
in EX_BINARY_OUTPUT) ' thrown in SetUp()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTest::TearDownTestCase() ' self.assertTrue(
'called as expected.' 'CxxExceptionInSetUpTest::TearDownTestSuite() '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTest destructor ' self.assertTrue(
'called as expected.' 'CxxExceptionInSetUpTest destructor '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTest::TearDown() ' self.assertTrue(
'called as expected.' 'CxxExceptionInSetUpTest::TearDown() '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('unexpected' not in EX_BINARY_OUTPUT, self.assert_('unexpected' not in EX_BINARY_OUTPUT,
'This failure belongs in this test only if ' 'This failure belongs in this test only if '
'"CxxExceptionInSetUpTest" (no quotes) ' '"CxxExceptionInSetUpTest" (no quotes) '
'appears on the same line as words "called unexpectedly"') 'appears on the same line as words "called unexpectedly"')
def testCatchesCxxExceptionsInTearDown(self): def testCatchesCxxExceptionsInTearDown(self):
self.assert_('C++ exception with description "Standard C++ exception"' self.assertTrue(
' thrown in TearDown()' 'C++ exception with description "Standard C++ exception"'
in EX_BINARY_OUTPUT) ' thrown in TearDown()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInTearDownTest::TearDownTestCase() ' self.assertTrue(
'called as expected.' 'CxxExceptionInTearDownTest::TearDownTestSuite() '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInTearDownTest destructor ' self.assertTrue(
'called as expected.' 'CxxExceptionInTearDownTest destructor '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
def testCatchesCxxExceptionsInTestBody(self): def testCatchesCxxExceptionsInTestBody(self):
self.assert_('C++ exception with description "Standard C++ exception"' self.assertTrue(
' thrown in the test body' 'C++ exception with description "Standard C++ exception"'
in EX_BINARY_OUTPUT) ' thrown in the test body' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInTestBodyTest::TearDownTestCase() ' self.assertTrue(
'called as expected.' 'CxxExceptionInTestBodyTest::TearDownTestSuite() '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInTestBodyTest destructor ' self.assertTrue(
'called as expected.' 'CxxExceptionInTestBodyTest destructor '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInTestBodyTest::TearDown() ' self.assertTrue(
'called as expected.' 'CxxExceptionInTestBodyTest::TearDown() '
in EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
def testCatchesNonStdCxxExceptions(self): def testCatchesNonStdCxxExceptions(self):
self.assert_('Unknown C++ exception thrown in the test body' self.assertTrue(
in EX_BINARY_OUTPUT) 'Unknown C++ exception thrown in the test body' in EX_BINARY_OUTPUT,
EX_BINARY_OUTPUT)
def testUnhandledCxxExceptionsAbortTheProgram(self): def testUnhandledCxxExceptionsAbortTheProgram(self):
# Filters out SEH exception tests on Windows. Unhandled SEH exceptions # Filters out SEH exception tests on Windows. Unhandled SEH exceptions
......
...@@ -64,19 +64,20 @@ class SehExceptionInDestructorTest : public Test { ...@@ -64,19 +64,20 @@ class SehExceptionInDestructorTest : public Test {
TEST_F(SehExceptionInDestructorTest, ThrowsExceptionInDestructor) {} TEST_F(SehExceptionInDestructorTest, ThrowsExceptionInDestructor) {}
class SehExceptionInSetUpTestCaseTest : public Test { class SehExceptionInSetUpTestSuiteTest : public Test {
public: public:
static void SetUpTestCase() { RaiseException(42, 0, 0, NULL); } static void SetUpTestSuite() { RaiseException(42, 0, 0, NULL); }
}; };
TEST_F(SehExceptionInSetUpTestCaseTest, ThrowsExceptionInSetUpTestCase) {} TEST_F(SehExceptionInSetUpTestSuiteTest, ThrowsExceptionInSetUpTestSuite) {}
class SehExceptionInTearDownTestCaseTest : public Test { class SehExceptionInTearDownTestSuiteTest : public Test {
public: public:
static void TearDownTestCase() { RaiseException(42, 0, 0, NULL); } static void TearDownTestSuite() { RaiseException(42, 0, 0, NULL); }
}; };
TEST_F(SehExceptionInTearDownTestCaseTest, ThrowsExceptionInTearDownTestCase) {} TEST_F(SehExceptionInTearDownTestSuiteTest,
ThrowsExceptionInTearDownTestSuite) {}
class SehExceptionInSetUpTest : public Test { class SehExceptionInSetUpTest : public Test {
protected: protected:
...@@ -109,9 +110,9 @@ class CxxExceptionInConstructorTest : public Test { ...@@ -109,9 +110,9 @@ class CxxExceptionInConstructorTest : public Test {
throw std::runtime_error("Standard C++ exception")); throw std::runtime_error("Standard C++ exception"));
} }
static void TearDownTestCase() { static void TearDownTestSuite() {
printf("%s", printf("%s",
"CxxExceptionInConstructorTest::TearDownTestCase() " "CxxExceptionInConstructorTest::TearDownTestSuite() "
"called as expected.\n"); "called as expected.\n");
} }
...@@ -137,65 +138,65 @@ TEST_F(CxxExceptionInConstructorTest, ThrowsExceptionInConstructor) { ...@@ -137,65 +138,65 @@ TEST_F(CxxExceptionInConstructorTest, ThrowsExceptionInConstructor) {
<< "called unexpectedly."; << "called unexpectedly.";
} }
class CxxExceptionInSetUpTestSuiteTest : public Test {
class CxxExceptionInSetUpTestCaseTest : public Test {
public: public:
CxxExceptionInSetUpTestCaseTest() { CxxExceptionInSetUpTestSuiteTest() {
printf("%s", printf("%s",
"CxxExceptionInSetUpTestCaseTest constructor " "CxxExceptionInSetUpTestSuiteTest constructor "
"called as expected.\n"); "called as expected.\n");
} }
static void SetUpTestCase() { static void SetUpTestSuite() {
throw std::runtime_error("Standard C++ exception"); throw std::runtime_error("Standard C++ exception");
} }
static void TearDownTestCase() { static void TearDownTestSuite() {
printf("%s", printf("%s",
"CxxExceptionInSetUpTestCaseTest::TearDownTestCase() " "CxxExceptionInSetUpTestSuiteTest::TearDownTestSuite() "
"called as expected.\n"); "called as expected.\n");
} }
protected: protected:
~CxxExceptionInSetUpTestCaseTest() override { ~CxxExceptionInSetUpTestSuiteTest() override {
printf("%s", printf("%s",
"CxxExceptionInSetUpTestCaseTest destructor " "CxxExceptionInSetUpTestSuiteTest destructor "
"called as expected.\n"); "called as expected.\n");
} }
void SetUp() override { void SetUp() override {
printf("%s", printf("%s",
"CxxExceptionInSetUpTestCaseTest::SetUp() " "CxxExceptionInSetUpTestSuiteTest::SetUp() "
"called as expected.\n"); "called as expected.\n");
} }
void TearDown() override { void TearDown() override {
printf("%s", printf("%s",
"CxxExceptionInSetUpTestCaseTest::TearDown() " "CxxExceptionInSetUpTestSuiteTest::TearDown() "
"called as expected.\n"); "called as expected.\n");
} }
}; };
TEST_F(CxxExceptionInSetUpTestCaseTest, ThrowsExceptionInSetUpTestCase) { TEST_F(CxxExceptionInSetUpTestSuiteTest, ThrowsExceptionInSetUpTestSuite) {
printf("%s", printf("%s",
"CxxExceptionInSetUpTestCaseTest test body " "CxxExceptionInSetUpTestSuiteTest test body "
"called as expected.\n"); "called as expected.\n");
} }
class CxxExceptionInTearDownTestCaseTest : public Test { class CxxExceptionInTearDownTestSuiteTest : public Test {
public: public:
static void TearDownTestCase() { static void TearDownTestSuite() {
throw std::runtime_error("Standard C++ exception"); throw std::runtime_error("Standard C++ exception");
} }
}; };
TEST_F(CxxExceptionInTearDownTestCaseTest, ThrowsExceptionInTearDownTestCase) {} TEST_F(CxxExceptionInTearDownTestSuiteTest,
ThrowsExceptionInTearDownTestSuite) {}
class CxxExceptionInSetUpTest : public Test { class CxxExceptionInSetUpTest : public Test {
public: public:
static void TearDownTestCase() { static void TearDownTestSuite() {
printf("%s", printf("%s",
"CxxExceptionInSetUpTest::TearDownTestCase() " "CxxExceptionInSetUpTest::TearDownTestSuite() "
"called as expected.\n"); "called as expected.\n");
} }
...@@ -222,9 +223,9 @@ TEST_F(CxxExceptionInSetUpTest, ThrowsExceptionInSetUp) { ...@@ -222,9 +223,9 @@ TEST_F(CxxExceptionInSetUpTest, ThrowsExceptionInSetUp) {
class CxxExceptionInTearDownTest : public Test { class CxxExceptionInTearDownTest : public Test {
public: public:
static void TearDownTestCase() { static void TearDownTestSuite() {
printf("%s", printf("%s",
"CxxExceptionInTearDownTest::TearDownTestCase() " "CxxExceptionInTearDownTest::TearDownTestSuite() "
"called as expected.\n"); "called as expected.\n");
} }
...@@ -244,9 +245,9 @@ TEST_F(CxxExceptionInTearDownTest, ThrowsExceptionInTearDown) {} ...@@ -244,9 +245,9 @@ TEST_F(CxxExceptionInTearDownTest, ThrowsExceptionInTearDown) {}
class CxxExceptionInTestBodyTest : public Test { class CxxExceptionInTestBodyTest : public Test {
public: public:
static void TearDownTestCase() { static void TearDownTestSuite() {
printf("%s", printf("%s",
"CxxExceptionInTestBodyTest::TearDownTestCase() " "CxxExceptionInTestBodyTest::TearDownTestSuite() "
"called as expected.\n"); "called as expected.\n");
} }
......
...@@ -41,7 +41,9 @@ using testing::internal::AlwaysTrue; ...@@ -41,7 +41,9 @@ using testing::internal::AlwaysTrue;
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST
# if GTEST_OS_WINDOWS # if GTEST_OS_WINDOWS
# include <fcntl.h> // For O_BINARY
# include <direct.h> // For chdir(). # include <direct.h> // For chdir().
# include <io.h>
# else # else
# include <unistd.h> # include <unistd.h>
# include <sys/wait.h> // For waitpid. # include <sys/wait.h> // For waitpid.
...@@ -139,7 +141,7 @@ class TestForDeathTest : public testing::Test { ...@@ -139,7 +141,7 @@ class TestForDeathTest : public testing::Test {
DieInside("MemberFunction"); DieInside("MemberFunction");
} }
// True iff MemberFunction() should die. // True if MemberFunction() should die.
bool should_die_; bool should_die_;
const FilePath original_dir_; const FilePath original_dir_;
}; };
...@@ -156,7 +158,7 @@ class MayDie { ...@@ -156,7 +158,7 @@ class MayDie {
} }
private: private:
// True iff MemberFunction() should die. // True if MemberFunction() should die.
bool should_die_; bool should_die_;
}; };
...@@ -202,6 +204,26 @@ int DieInDebugElse12(int* sideeffect) { ...@@ -202,6 +204,26 @@ int DieInDebugElse12(int* sideeffect) {
return 12; return 12;
} }
# if GTEST_OS_WINDOWS
// Death in dbg due to Windows CRT assertion failure, not opt.
int DieInCRTDebugElse12(int* sideeffect) {
if (sideeffect) *sideeffect = 12;
// Create an invalid fd by closing a valid one
int fdpipe[2];
EXPECT_EQ(_pipe(fdpipe, 256, O_BINARY), 0);
EXPECT_EQ(_close(fdpipe[0]), 0);
EXPECT_EQ(_close(fdpipe[1]), 0);
// _dup() should crash in debug mode
EXPECT_EQ(_dup(fdpipe[0]), -1);
return 12;
}
#endif // GTEST_OS_WINDOWS
# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA # if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
// Tests the ExitedWithCode predicate. // Tests the ExitedWithCode predicate.
...@@ -493,17 +515,6 @@ TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) { ...@@ -493,17 +515,6 @@ TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) {
const testing::internal::RE regex(regex_c_str); const testing::internal::RE regex(regex_c_str);
EXPECT_DEATH(GlobalFunction(), regex); EXPECT_DEATH(GlobalFunction(), regex);
# if GTEST_HAS_GLOBAL_STRING
const ::string regex_str(regex_c_str);
EXPECT_DEATH(GlobalFunction(), regex_str);
// This one is tricky; a temporary pointer into another temporary. Reference
// lifetime extension of the pointer is not sufficient.
EXPECT_DEATH(GlobalFunction(), ::string(regex_c_str).c_str());
# endif // GTEST_HAS_GLOBAL_STRING
# if !GTEST_USES_PCRE # if !GTEST_USES_PCRE
const ::std::string regex_std_str(regex_c_str); const ::std::string regex_std_str(regex_c_str);
...@@ -562,7 +573,7 @@ TEST_F(TestForDeathTest, ErrorMessageMismatch) { ...@@ -562,7 +573,7 @@ TEST_F(TestForDeathTest, ErrorMessageMismatch) {
}, "died but not with expected error"); }, "died but not with expected error");
} }
// On exit, *aborted will be true iff the EXPECT_DEATH() statement // On exit, *aborted will be true if the EXPECT_DEATH() statement
// aborted the function. // aborted the function.
void ExpectDeathTestHelper(bool* aborted) { void ExpectDeathTestHelper(bool* aborted) {
*aborted = true; *aborted = true;
...@@ -643,6 +654,40 @@ TEST_F(TestForDeathTest, TestExpectDebugDeath) { ...@@ -643,6 +654,40 @@ TEST_F(TestForDeathTest, TestExpectDebugDeath) {
# endif # endif
} }
# if GTEST_OS_WINDOWS
// Tests that EXPECT_DEBUG_DEATH works as expected when in debug mode
// the Windows CRT crashes the process with an assertion failure.
// 1. Asserts on death.
// 2. Has no side effect (doesn't pop up a window or wait for user input).
//
// And in opt mode, it:
// 1. Has side effects but does not assert.
TEST_F(TestForDeathTest, CRTDebugDeath) {
int sideeffect = 0;
// Put the regex in a local variable to make sure we don't get an "unused"
// warning in opt mode.
const char* regex = "dup.* : Assertion failed";
EXPECT_DEBUG_DEATH(DieInCRTDebugElse12(&sideeffect), regex)
<< "Must accept a streamed message";
# ifdef NDEBUG
// Checks that the assignment occurs in opt mode (sideeffect).
EXPECT_EQ(12, sideeffect);
# else
// Checks that the assignment does not occur in dbg mode (no sideeffect).
EXPECT_EQ(0, sideeffect);
# endif
}
# endif // GTEST_OS_WINDOWS
// Tests that ASSERT_DEBUG_DEATH works as expected, that is, you can stream a // Tests that ASSERT_DEBUG_DEATH works as expected, that is, you can stream a
// message to it, and in debug mode it: // message to it, and in debug mode it:
// 1. Asserts on death. // 1. Asserts on death.
...@@ -895,10 +940,12 @@ class MockDeathTestFactory : public DeathTestFactory { ...@@ -895,10 +940,12 @@ class MockDeathTestFactory : public DeathTestFactory {
int AssumeRoleCalls() const { return assume_role_calls_; } int AssumeRoleCalls() const { return assume_role_calls_; }
int WaitCalls() const { return wait_calls_; } int WaitCalls() const { return wait_calls_; }
size_t PassedCalls() const { return passed_args_.size(); } size_t PassedCalls() const { return passed_args_.size(); }
bool PassedArgument(int n) const { return passed_args_[n]; } bool PassedArgument(int n) const {
return passed_args_[static_cast<size_t>(n)];
}
size_t AbortCalls() const { return abort_args_.size(); } size_t AbortCalls() const { return abort_args_.size(); }
DeathTest::AbortReason AbortArgument(int n) const { DeathTest::AbortReason AbortArgument(int n) const {
return abort_args_[n]; return abort_args_[static_cast<size_t>(n)];
} }
bool TestDeleted() const { return test_deleted_; } bool TestDeleted() const { return test_deleted_; }
...@@ -1017,12 +1064,12 @@ class MacroLogicDeathTest : public testing::Test { ...@@ -1017,12 +1064,12 @@ class MacroLogicDeathTest : public testing::Test {
static testing::internal::ReplaceDeathTestFactory* replacer_; static testing::internal::ReplaceDeathTestFactory* replacer_;
static MockDeathTestFactory* factory_; static MockDeathTestFactory* factory_;
static void SetUpTestCase() { static void SetUpTestSuite() {
factory_ = new MockDeathTestFactory; factory_ = new MockDeathTestFactory;
replacer_ = new testing::internal::ReplaceDeathTestFactory(factory_); replacer_ = new testing::internal::ReplaceDeathTestFactory(factory_);
} }
static void TearDownTestCase() { static void TearDownTestSuite() {
delete replacer_; delete replacer_;
replacer_ = nullptr; replacer_ = nullptr;
delete factory_; delete factory_;
...@@ -1281,9 +1328,6 @@ TEST(ParseNaturalNumberTest, WorksForShorterIntegers) { ...@@ -1281,9 +1328,6 @@ TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
# if GTEST_OS_WINDOWS # if GTEST_OS_WINDOWS
TEST(EnvironmentTest, HandleFitsIntoSizeT) { TEST(EnvironmentTest, HandleFitsIntoSizeT) {
// FIXME: Remove this test after this condition is verified
// in a static assertion in gtest-death-test.cc in the function
// GetStatusFileDescriptor.
ASSERT_TRUE(sizeof(HANDLE) <= sizeof(size_t)); ASSERT_TRUE(sizeof(HANDLE) <= sizeof(size_t));
} }
# endif // GTEST_OS_WINDOWS # endif // GTEST_OS_WINDOWS
......
...@@ -68,7 +68,7 @@ TEST(CxxExceptionDeathTest, PrintsMessageForStdExceptions) { ...@@ -68,7 +68,7 @@ TEST(CxxExceptionDeathTest, PrintsMessageForStdExceptions) {
"exceptional message"); "exceptional message");
// Verifies that the location is mentioned in the failure text. // Verifies that the location is mentioned in the failure text.
EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw TestException(), ""), EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw TestException(), ""),
"googletest-death-test_ex_test.cc"); __FILE__);
} }
# endif // GTEST_HAS_EXCEPTIONS # endif // GTEST_HAS_EXCEPTIONS
......
...@@ -50,8 +50,6 @@ namespace internal { ...@@ -50,8 +50,6 @@ namespace internal {
namespace { namespace {
#if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
// FIXME: Move these to the POSIX adapter section in
// gtest-port.h.
// Windows CE doesn't have the remove C function. // Windows CE doesn't have the remove C function.
int remove(const char* path) { int remove(const char* path) {
......
...@@ -125,8 +125,8 @@ TEST_P(ParamTest, TestX) { ...@@ -125,8 +125,8 @@ TEST_P(ParamTest, TestX) {
TEST_P(ParamTest, TestY) { TEST_P(ParamTest, TestY) {
} }
INSTANTIATE_TEST_CASE_P(SeqP, ParamTest, testing::Values(1, 2)); INSTANTIATE_TEST_SUITE_P(SeqP, ParamTest, testing::Values(1, 2));
INSTANTIATE_TEST_CASE_P(SeqQ, ParamTest, testing::Values(5, 6)); INSTANTIATE_TEST_SUITE_P(SeqQ, ParamTest, testing::Values(5, 6));
} // namespace } // namespace
......
...@@ -40,24 +40,41 @@ GTEST_OUTPUT_1_TEST = 'gtest_xml_outfile1_test_' ...@@ -40,24 +40,41 @@ GTEST_OUTPUT_1_TEST = 'gtest_xml_outfile1_test_'
GTEST_OUTPUT_2_TEST = 'gtest_xml_outfile2_test_' GTEST_OUTPUT_2_TEST = 'gtest_xml_outfile2_test_'
EXPECTED_1 = { EXPECTED_1 = {
u'tests': 1, u'tests':
u'failures': 0, 1,
u'disabled': 0, u'failures':
u'errors': 0, 0,
u'time': u'*', u'disabled':
u'timestamp': u'*', 0,
u'name': u'AllTests', u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'name':
u'AllTests',
u'testsuites': [{ u'testsuites': [{
u'name': u'PropertyOne', u'name':
u'tests': 1, u'PropertyOne',
u'failures': 0, u'tests':
u'disabled': 0, 1,
u'errors': 0, u'failures':
u'time': u'*', 0,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{ u'testsuite': [{
u'name': u'TestSomeProperties', u'name': u'TestSomeProperties',
u'status': u'RUN', u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*', u'time': u'*',
u'timestamp': u'*',
u'classname': u'PropertyOne', u'classname': u'PropertyOne',
u'SetUpProp': u'1', u'SetUpProp': u'1',
u'TestSomeProperty': u'1', u'TestSomeProperty': u'1',
...@@ -67,23 +84,40 @@ EXPECTED_1 = { ...@@ -67,23 +84,40 @@ EXPECTED_1 = {
} }
EXPECTED_2 = { EXPECTED_2 = {
u'tests': 1, u'tests':
u'failures': 0, 1,
u'disabled': 0, u'failures':
u'errors': 0, 0,
u'time': u'*', u'disabled':
u'timestamp': u'*', 0,
u'name': u'AllTests', u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'name':
u'AllTests',
u'testsuites': [{ u'testsuites': [{
u'name': u'PropertyTwo', u'name':
u'tests': 1, u'PropertyTwo',
u'failures': 0, u'tests':
u'disabled': 0, 1,
u'errors': 0, u'failures':
u'time': u'*', 0,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{ u'testsuite': [{
u'name': u'TestSomeProperties', u'name': u'TestSomeProperties',
u'status': u'RUN', u'status': u'RUN',
u'result': u'COMPLETED',
u'timestamp': u'*',
u'time': u'*', u'time': u'*',
u'classname': u'PropertyTwo', u'classname': u'PropertyTwo',
u'SetUpProp': u'2', u'SetUpProp': u'2',
...@@ -136,11 +170,6 @@ class GTestJsonOutFilesTest(gtest_test_utils.TestCase): ...@@ -136,11 +170,6 @@ class GTestJsonOutFilesTest(gtest_test_utils.TestCase):
self.assert_(p.exited) self.assert_(p.exited)
self.assertEquals(0, p.exit_code) self.assertEquals(0, p.exit_code)
# FIXME: libtool causes the built test binary to be
# named lt-gtest_xml_outfiles_test_ instead of
# gtest_xml_outfiles_test_. To account for this possibility, we
# allow both names in the following code. We should remove this
# when libtool replacement tool is ready.
output_file_name1 = test_name + '.json' output_file_name1 = test_name + '.json'
output_file1 = os.path.join(self.output_dir_, output_file_name1) output_file1 = os.path.join(self.output_dir_, output_file_name1)
output_file_name2 = 'lt-' + output_file_name1 output_file_name2 = 'lt-' + output_file_name1
......
...@@ -57,386 +57,530 @@ else: ...@@ -57,386 +57,530 @@ else:
STACK_TRACE_TEMPLATE = '' STACK_TRACE_TEMPLATE = ''
EXPECTED_NON_EMPTY = { EXPECTED_NON_EMPTY = {
u'tests': 24, u'tests':
u'failures': 4, 24,
u'disabled': 2, u'failures':
u'errors': 0, 4,
u'timestamp': u'*', u'disabled':
u'time': u'*', 2,
u'ad_hoc_property': u'42', u'errors':
u'name': u'AllTests', 0,
u'testsuites': [ u'timestamp':
{ u'*',
u'name': u'SuccessfulTest', u'time':
u'tests': 1, u'*',
u'failures': 0, u'ad_hoc_property':
u'disabled': 0, u'42',
u'errors': 0, u'name':
u'AllTests',
u'testsuites': [{
u'name':
u'SuccessfulTest',
u'tests':
1,
u'failures':
0,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{
u'name': u'Succeeds',
u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'SuccessfulTest'
u'name': u'Succeeds', }]
u'status': u'RUN', }, {
u'time': u'*', u'name':
u'classname': u'SuccessfulTest' u'FailedTest',
} u'tests':
] 1,
}, u'failures':
{ 1,
u'name': u'FailedTest', u'disabled':
u'tests': 1, 0,
u'failures': 1, u'errors':
u'disabled': 0, 0,
u'errors': 0, u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{
u'name':
u'Fails',
u'status':
u'RUN',
u'result':
u'COMPLETED',
u'time':
u'*',
u'timestamp':
u'*',
u'classname':
u'FailedTest',
u'failures': [{
u'failure': u'gtest_xml_output_unittest_.cc:*\n'
u'Expected equality of these values:\n'
u' 1\n 2' + STACK_TRACE_TEMPLATE,
u'type': u''
}]
}]
}, {
u'name':
u'DisabledTest',
u'tests':
1,
u'failures':
0,
u'disabled':
1,
u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{
u'name': u'DISABLED_test_not_run',
u'status': u'NOTRUN',
u'result': u'SUPPRESSED',
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'DisabledTest'
u'name': u'Fails', }]
u'status': u'RUN', }, {
u'time': u'*', u'name':
u'classname': u'FailedTest', u'SkippedTest',
u'failures': [ u'tests':
{ 1,
u'failure': u'failures':
u'gtest_xml_output_unittest_.cc:*\n' 0,
u'Expected equality of these values:\n' u'disabled':
u' 1\n 2' + STACK_TRACE_TEMPLATE, 0,
u'type': u'' u'errors':
} 0,
] u'time':
} u'*',
] u'timestamp':
}, u'*',
{ u'testsuite': [{
u'name': u'DisabledTest', u'name': u'Skipped',
u'tests': 1, u'status': u'RUN',
u'failures': 0, u'result': u'SKIPPED',
u'disabled': 1,
u'errors': 0,
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'SkippedTest'
u'name': u'DISABLED_test_not_run', }]
u'status': u'NOTRUN', }, {
u'time': u'*', u'name':
u'classname': u'DisabledTest' u'MixedResultTest',
} u'tests':
] 3,
}, u'failures':
{ 1,
u'name': u'SkippedTest', u'disabled':
u'tests': 1, 1,
u'failures': 0, u'errors':
u'disabled': 0, 0,
u'errors': 0, u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{
u'name': u'Succeeds',
u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'MixedResultTest'
u'name': u'Skipped', }, {
u'status': u'SKIPPED', u'name':
u'time': u'*', u'Fails',
u'classname': u'SkippedTest' u'status':
} u'RUN',
] u'result':
}, u'COMPLETED',
{ u'time':
u'name': u'MixedResultTest', u'*',
u'tests': 3, u'timestamp':
u'failures': 1, u'*',
u'disabled': 1, u'classname':
u'errors': 0, u'MixedResultTest',
u'failures': [{
u'failure': u'gtest_xml_output_unittest_.cc:*\n'
u'Expected equality of these values:\n'
u' 1\n 2' + STACK_TRACE_TEMPLATE,
u'type': u''
}, {
u'failure': u'gtest_xml_output_unittest_.cc:*\n'
u'Expected equality of these values:\n'
u' 2\n 3' + STACK_TRACE_TEMPLATE,
u'type': u''
}]
}, {
u'name': u'DISABLED_test',
u'status': u'NOTRUN',
u'result': u'SUPPRESSED',
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'MixedResultTest'
u'name': u'Succeeds', }]
u'status': u'RUN', }, {
u'time': u'*', u'name':
u'classname': u'MixedResultTest' u'XmlQuotingTest',
}, u'tests':
{ 1,
u'name': u'Fails', u'failures':
u'status': u'RUN', 1,
u'time': u'*', u'disabled':
u'classname': u'MixedResultTest', 0,
u'failures': [ u'errors':
{ 0,
u'failure': u'time':
u'gtest_xml_output_unittest_.cc:*\n' u'*',
u'Expected equality of these values:\n' u'timestamp':
u' 1\n 2' + STACK_TRACE_TEMPLATE, u'*',
u'type': u'' u'testsuite': [{
}, u'name':
{ u'OutputsCData',
u'failure': u'status':
u'gtest_xml_output_unittest_.cc:*\n' u'RUN',
u'Expected equality of these values:\n' u'result':
u' 2\n 3' + STACK_TRACE_TEMPLATE, u'COMPLETED',
u'type': u'' u'time':
} u'*',
] u'timestamp':
}, u'*',
{ u'classname':
u'name': u'DISABLED_test', u'XmlQuotingTest',
u'status': u'NOTRUN', u'failures': [{
u'time': u'*', u'failure': u'gtest_xml_output_unittest_.cc:*\n'
u'classname': u'MixedResultTest' u'Failed\nXML output: <?xml encoding="utf-8">'
} u'<top><![CDATA[cdata text]]></top>' +
] STACK_TRACE_TEMPLATE,
}, u'type': u''
{ }]
u'name': u'XmlQuotingTest', }]
u'tests': 1, }, {
u'failures': 1, u'name':
u'disabled': 0, u'InvalidCharactersTest',
u'errors': 0, u'tests':
1,
u'failures':
1,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{
u'name':
u'InvalidCharactersInMessage',
u'status':
u'RUN',
u'result':
u'COMPLETED',
u'time':
u'*',
u'timestamp':
u'*',
u'classname':
u'InvalidCharactersTest',
u'failures': [{
u'failure': u'gtest_xml_output_unittest_.cc:*\n'
u'Failed\nInvalid characters in brackets'
u' [\x01\x02]' + STACK_TRACE_TEMPLATE,
u'type': u''
}]
}]
}, {
u'name':
u'PropertyRecordingTest',
u'tests':
4,
u'failures':
0,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'SetUpTestSuite':
u'yes',
u'TearDownTestSuite':
u'aye',
u'testsuite': [{
u'name': u'OneProperty',
u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'PropertyRecordingTest',
u'name': u'OutputsCData', u'key_1': u'1'
u'status': u'RUN', }, {
u'time': u'*', u'name': u'IntValuedProperty',
u'classname': u'XmlQuotingTest', u'status': u'RUN',
u'failures': [ u'result': u'COMPLETED',
{
u'failure':
u'gtest_xml_output_unittest_.cc:*\n'
u'Failed\nXML output: <?xml encoding="utf-8">'
u'<top><![CDATA[cdata text]]></top>' +
STACK_TRACE_TEMPLATE,
u'type': u''
}
]
}
]
},
{
u'name': u'InvalidCharactersTest',
u'tests': 1,
u'failures': 1,
u'disabled': 0,
u'errors': 0,
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'PropertyRecordingTest',
u'name': u'InvalidCharactersInMessage', u'key_int': u'1'
u'status': u'RUN', }, {
u'time': u'*', u'name': u'ThreeProperties',
u'classname': u'InvalidCharactersTest', u'status': u'RUN',
u'failures': [ u'result': u'COMPLETED',
{
u'failure':
u'gtest_xml_output_unittest_.cc:*\n'
u'Failed\nInvalid characters in brackets'
u' [\x01\x02]' + STACK_TRACE_TEMPLATE,
u'type': u''
}
]
}
]
},
{
u'name': u'PropertyRecordingTest',
u'tests': 4,
u'failures': 0,
u'disabled': 0,
u'errors': 0,
u'time': u'*', u'time': u'*',
u'SetUpTestCase': u'yes', u'timestamp': u'*',
u'TearDownTestCase': u'aye', u'classname': u'PropertyRecordingTest',
u'testsuite': [ u'key_1': u'1',
{ u'key_2': u'2',
u'name': u'OneProperty', u'key_3': u'3'
u'status': u'RUN', }, {
u'time': u'*', u'name': u'TwoValuesForOneKeyUsesLastValue',
u'classname': u'PropertyRecordingTest', u'status': u'RUN',
u'key_1': u'1' u'result': u'COMPLETED',
},
{
u'name': u'IntValuedProperty',
u'status': u'RUN',
u'time': u'*',
u'classname': u'PropertyRecordingTest',
u'key_int': u'1'
},
{
u'name': u'ThreeProperties',
u'status': u'RUN',
u'time': u'*',
u'classname': u'PropertyRecordingTest',
u'key_1': u'1',
u'key_2': u'2',
u'key_3': u'3'
},
{
u'name': u'TwoValuesForOneKeyUsesLastValue',
u'status': u'RUN',
u'time': u'*',
u'classname': u'PropertyRecordingTest',
u'key_1': u'2'
}
]
},
{
u'name': u'NoFixtureTest',
u'tests': 3,
u'failures': 0,
u'disabled': 0,
u'errors': 0,
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'PropertyRecordingTest',
u'name': u'RecordProperty', u'key_1': u'2'
u'status': u'RUN', }]
u'time': u'*', }, {
u'classname': u'NoFixtureTest', u'name':
u'key': u'1' u'NoFixtureTest',
}, u'tests':
{ 3,
u'name': u'ExternalUtilityThatCallsRecordIntValuedProperty', u'failures':
u'status': u'RUN', 0,
u'time': u'*', u'disabled':
u'classname': u'NoFixtureTest', 0,
u'key_for_utility_int': u'1' u'errors':
}, 0,
{ u'time':
u'name': u'*',
u'ExternalUtilityThatCallsRecordStringValuedProperty', u'timestamp':
u'status': u'RUN', u'*',
u'time': u'*', u'testsuite': [{
u'classname': u'NoFixtureTest', u'name': u'RecordProperty',
u'key_for_utility_string': u'1' u'status': u'RUN',
} u'result': u'COMPLETED',
]
},
{
u'name': u'TypedTest/0',
u'tests': 1,
u'failures': 0,
u'disabled': 0,
u'errors': 0,
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'NoFixtureTest',
u'name': u'HasTypeParamAttribute', u'key': u'1'
u'type_param': u'int', }, {
u'status': u'RUN', u'name': u'ExternalUtilityThatCallsRecordIntValuedProperty',
u'time': u'*', u'status': u'RUN',
u'classname': u'TypedTest/0' u'result': u'COMPLETED',
}
]
},
{
u'name': u'TypedTest/1',
u'tests': 1,
u'failures': 0,
u'disabled': 0,
u'errors': 0,
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'NoFixtureTest',
u'name': u'HasTypeParamAttribute', u'key_for_utility_int': u'1'
u'type_param': u'long', }, {
u'status': u'RUN', u'name': u'ExternalUtilityThatCallsRecordStringValuedProperty',
u'time': u'*', u'status': u'RUN',
u'classname': u'TypedTest/1' u'result': u'COMPLETED',
} u'time': u'*',
] u'timestamp': u'*',
}, u'classname': u'NoFixtureTest',
{ u'key_for_utility_string': u'1'
u'name': u'Single/TypeParameterizedTestCase/0', }]
u'tests': 1, }, {
u'failures': 0, u'name':
u'disabled': 0, u'TypedTest/0',
u'errors': 0, u'tests':
1,
u'failures':
0,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{
u'name': u'HasTypeParamAttribute',
u'type_param': u'int',
u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*',
u'timestamp': u'*',
u'classname': u'TypedTest/0'
}]
}, {
u'name':
u'TypedTest/1',
u'tests':
1,
u'failures':
0,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{
u'name': u'HasTypeParamAttribute',
u'type_param': u'long',
u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*',
u'timestamp': u'*',
u'classname': u'TypedTest/1'
}]
}, {
u'name':
u'Single/TypeParameterizedTestSuite/0',
u'tests':
1,
u'failures':
0,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{
u'name': u'HasTypeParamAttribute',
u'type_param': u'int',
u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*',
u'timestamp': u'*',
u'classname': u'Single/TypeParameterizedTestSuite/0'
}]
}, {
u'name':
u'Single/TypeParameterizedTestSuite/1',
u'tests':
1,
u'failures':
0,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{
u'name': u'HasTypeParamAttribute',
u'type_param': u'long',
u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*',
u'timestamp': u'*',
u'classname': u'Single/TypeParameterizedTestSuite/1'
}]
}, {
u'name':
u'Single/ValueParamTest',
u'tests':
4,
u'failures':
0,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{
u'name': u'HasValueParamAttribute/0',
u'value_param': u'33',
u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*',
u'timestamp': u'*',
u'classname': u'Single/ValueParamTest'
}, {
u'name': u'HasValueParamAttribute/1',
u'value_param': u'42',
u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'Single/ValueParamTest'
u'name': u'HasTypeParamAttribute', }, {
u'type_param': u'int', u'name': u'AnotherTestThatHasValueParamAttribute/0',
u'status': u'RUN', u'value_param': u'33',
u'time': u'*', u'status': u'RUN',
u'classname': u'Single/TypeParameterizedTestCase/0' u'result': u'COMPLETED',
}
]
},
{
u'name': u'Single/TypeParameterizedTestCase/1',
u'tests': 1,
u'failures': 0,
u'disabled': 0,
u'errors': 0,
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'Single/ValueParamTest'
u'name': u'HasTypeParamAttribute', }, {
u'type_param': u'long', u'name': u'AnotherTestThatHasValueParamAttribute/1',
u'status': u'RUN', u'value_param': u'42',
u'time': u'*', u'status': u'RUN',
u'classname': u'Single/TypeParameterizedTestCase/1' u'result': u'COMPLETED',
}
]
},
{
u'name': u'Single/ValueParamTest',
u'tests': 4,
u'failures': 0,
u'disabled': 0,
u'errors': 0,
u'time': u'*', u'time': u'*',
u'testsuite': [ u'timestamp': u'*',
{ u'classname': u'Single/ValueParamTest'
u'name': u'HasValueParamAttribute/0', }]
u'value_param': u'33', }]
u'status': u'RUN',
u'time': u'*',
u'classname': u'Single/ValueParamTest'
},
{
u'name': u'HasValueParamAttribute/1',
u'value_param': u'42',
u'status': u'RUN',
u'time': u'*',
u'classname': u'Single/ValueParamTest'
},
{
u'name': u'AnotherTestThatHasValueParamAttribute/0',
u'value_param': u'33',
u'status': u'RUN',
u'time': u'*',
u'classname': u'Single/ValueParamTest'
},
{
u'name': u'AnotherTestThatHasValueParamAttribute/1',
u'value_param': u'42',
u'status': u'RUN',
u'time': u'*',
u'classname': u'Single/ValueParamTest'
}
]
}
]
} }
EXPECTED_FILTERED = { EXPECTED_FILTERED = {
u'tests': 1, u'tests':
u'failures': 0, 1,
u'disabled': 0, u'failures':
u'errors': 0, 0,
u'time': u'*', u'disabled':
u'timestamp': u'*', 0,
u'name': u'AllTests', u'errors':
u'ad_hoc_property': u'42', 0,
u'time':
u'*',
u'timestamp':
u'*',
u'name':
u'AllTests',
u'ad_hoc_property':
u'42',
u'testsuites': [{ u'testsuites': [{
u'name': u'SuccessfulTest', u'name':
u'tests': 1, u'SuccessfulTest',
u'failures': 0, u'tests':
u'disabled': 0, 1,
u'errors': 0, u'failures':
u'time': u'*', 0,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'testsuite': [{ u'testsuite': [{
u'name': u'Succeeds', u'name': u'Succeeds',
u'status': u'RUN', u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*', u'time': u'*',
u'timestamp': u'*',
u'classname': u'SuccessfulTest', u'classname': u'SuccessfulTest',
}] }]
}], }],
......
...@@ -99,7 +99,7 @@ TEST_P(ValueParamTest, TestA) { ...@@ -99,7 +99,7 @@ TEST_P(ValueParamTest, TestA) {
TEST_P(ValueParamTest, TestB) { TEST_P(ValueParamTest, TestB) {
} }
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_SUITE_P(
MyInstantiation, ValueParamTest, MyInstantiation, ValueParamTest,
testing::Values(MyType("one line"), testing::Values(MyType("one line"),
MyType("two\nlines"), MyType("two\nlines"),
...@@ -123,7 +123,7 @@ class MyArray { ...@@ -123,7 +123,7 @@ class MyArray {
typedef testing::Types<VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName, // NOLINT typedef testing::Types<VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName, // NOLINT
int*, MyArray<bool, 42> > MyTypes; int*, MyArray<bool, 42> > MyTypes;
TYPED_TEST_CASE(TypedTest, MyTypes); TYPED_TEST_SUITE(TypedTest, MyTypes);
TYPED_TEST(TypedTest, TestA) { TYPED_TEST(TypedTest, TestA) {
} }
...@@ -137,7 +137,7 @@ template <typename T> ...@@ -137,7 +137,7 @@ template <typename T>
class TypeParamTest : public testing::Test { class TypeParamTest : public testing::Test {
}; };
TYPED_TEST_CASE_P(TypeParamTest); TYPED_TEST_SUITE_P(TypeParamTest);
TYPED_TEST_P(TypeParamTest, TestA) { TYPED_TEST_P(TypeParamTest, TestA) {
} }
...@@ -145,9 +145,9 @@ TYPED_TEST_P(TypeParamTest, TestA) { ...@@ -145,9 +145,9 @@ TYPED_TEST_P(TypeParamTest, TestA) {
TYPED_TEST_P(TypeParamTest, TestB) { TYPED_TEST_P(TypeParamTest, TestB) {
} }
REGISTER_TYPED_TEST_CASE_P(TypeParamTest, TestA, TestB); REGISTER_TYPED_TEST_SUITE_P(TypeParamTest, TestA, TestB);
INSTANTIATE_TYPED_TEST_CASE_P(My, TypeParamTest, MyTypes); INSTANTIATE_TYPED_TEST_SUITE_P(My, TypeParamTest, MyTypes);
int main(int argc, char **argv) { int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
......
...@@ -35,12 +35,13 @@ ...@@ -35,12 +35,13 @@
#include <vector> #include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gtest/internal/custom/gtest.h"
using ::testing::AddGlobalTestEnvironment; using ::testing::AddGlobalTestEnvironment;
using ::testing::Environment; using ::testing::Environment;
using ::testing::InitGoogleTest; using ::testing::InitGoogleTest;
using ::testing::Test; using ::testing::Test;
using ::testing::TestCase; using ::testing::TestSuite;
using ::testing::TestEventListener; using ::testing::TestEventListener;
using ::testing::TestInfo; using ::testing::TestInfo;
using ::testing::TestPartResult; using ::testing::TestPartResult;
...@@ -76,10 +77,11 @@ class EventRecordingListener : public TestEventListener { ...@@ -76,10 +77,11 @@ class EventRecordingListener : public TestEventListener {
void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override { void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpEnd")); g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpEnd"));
} }
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void OnTestCaseStart(const TestCase& /*test_case*/) override { void OnTestCaseStart(const TestCase& /*test_case*/) override {
g_events->push_back(GetFullMethodName("OnTestCaseStart")); g_events->push_back(GetFullMethodName("OnTestCaseStart"));
} }
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void OnTestStart(const TestInfo& /*test_info*/) override { void OnTestStart(const TestInfo& /*test_info*/) override {
g_events->push_back(GetFullMethodName("OnTestStart")); g_events->push_back(GetFullMethodName("OnTestStart"));
...@@ -93,9 +95,11 @@ class EventRecordingListener : public TestEventListener { ...@@ -93,9 +95,11 @@ class EventRecordingListener : public TestEventListener {
g_events->push_back(GetFullMethodName("OnTestEnd")); g_events->push_back(GetFullMethodName("OnTestEnd"));
} }
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void OnTestCaseEnd(const TestCase& /*test_case*/) override { void OnTestCaseEnd(const TestCase& /*test_case*/) override {
g_events->push_back(GetFullMethodName("OnTestCaseEnd")); g_events->push_back(GetFullMethodName("OnTestCaseEnd"));
} }
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override { void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownStart")); g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownStart"));
...@@ -125,6 +129,78 @@ class EventRecordingListener : public TestEventListener { ...@@ -125,6 +129,78 @@ class EventRecordingListener : public TestEventListener {
std::string name_; std::string name_;
}; };
// This listener is using OnTestSuiteStart, OnTestSuiteEnd API
class EventRecordingListener2 : public TestEventListener {
public:
explicit EventRecordingListener2(const char* name) : name_(name) {}
protected:
void OnTestProgramStart(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnTestProgramStart"));
}
void OnTestIterationStart(const UnitTest& /*unit_test*/,
int iteration) override {
Message message;
message << GetFullMethodName("OnTestIterationStart") << "(" << iteration
<< ")";
g_events->push_back(message.GetString());
}
void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpStart"));
}
void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpEnd"));
}
void OnTestSuiteStart(const TestSuite& /*test_suite*/) override {
g_events->push_back(GetFullMethodName("OnTestSuiteStart"));
}
void OnTestStart(const TestInfo& /*test_info*/) override {
g_events->push_back(GetFullMethodName("OnTestStart"));
}
void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {
g_events->push_back(GetFullMethodName("OnTestPartResult"));
}
void OnTestEnd(const TestInfo& /*test_info*/) override {
g_events->push_back(GetFullMethodName("OnTestEnd"));
}
void OnTestSuiteEnd(const TestSuite& /*test_suite*/) override {
g_events->push_back(GetFullMethodName("OnTestSuiteEnd"));
}
void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownStart"));
}
void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownEnd"));
}
void OnTestIterationEnd(const UnitTest& /*unit_test*/,
int iteration) override {
Message message;
message << GetFullMethodName("OnTestIterationEnd") << "(" << iteration
<< ")";
g_events->push_back(message.GetString());
}
void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnTestProgramEnd"));
}
private:
std::string GetFullMethodName(const char* name) { return name_ + "." + name; }
std::string name_;
};
class EnvironmentInvocationCatcher : public Environment { class EnvironmentInvocationCatcher : public Environment {
protected: protected:
void SetUp() override { g_events->push_back("Environment::SetUp"); } void SetUp() override { g_events->push_back("Environment::SetUp"); }
...@@ -134,12 +210,12 @@ class EnvironmentInvocationCatcher : public Environment { ...@@ -134,12 +210,12 @@ class EnvironmentInvocationCatcher : public Environment {
class ListenerTest : public Test { class ListenerTest : public Test {
protected: protected:
static void SetUpTestCase() { static void SetUpTestSuite() {
g_events->push_back("ListenerTest::SetUpTestCase"); g_events->push_back("ListenerTest::SetUpTestSuite");
} }
static void TearDownTestCase() { static void TearDownTestSuite() {
g_events->push_back("ListenerTest::TearDownTestCase"); g_events->push_back("ListenerTest::TearDownTestSuite");
} }
void SetUp() override { g_events->push_back("ListenerTest::SetUp"); } void SetUp() override { g_events->push_back("ListenerTest::SetUp"); }
...@@ -165,6 +241,7 @@ TEST_F(ListenerTest, DoesBar) { ...@@ -165,6 +241,7 @@ TEST_F(ListenerTest, DoesBar) {
using ::testing::internal::EnvironmentInvocationCatcher; using ::testing::internal::EnvironmentInvocationCatcher;
using ::testing::internal::EventRecordingListener; using ::testing::internal::EventRecordingListener;
using ::testing::internal::EventRecordingListener2;
void VerifyResults(const std::vector<std::string>& data, void VerifyResults(const std::vector<std::string>& data,
const char* const* expected_data, const char* const* expected_data,
...@@ -199,6 +276,8 @@ int main(int argc, char **argv) { ...@@ -199,6 +276,8 @@ int main(int argc, char **argv) {
new EventRecordingListener("1st")); new EventRecordingListener("1st"));
UnitTest::GetInstance()->listeners().Append( UnitTest::GetInstance()->listeners().Append(
new EventRecordingListener("2nd")); new EventRecordingListener("2nd"));
UnitTest::GetInstance()->listeners().Append(
new EventRecordingListener2("3rd"));
AddGlobalTestEnvironment(new EnvironmentInvocationCatcher); AddGlobalTestEnvironment(new EnvironmentInvocationCatcher);
...@@ -208,88 +287,224 @@ int main(int argc, char **argv) { ...@@ -208,88 +287,224 @@ int main(int argc, char **argv) {
::testing::GTEST_FLAG(repeat) = 2; ::testing::GTEST_FLAG(repeat) = 2;
int ret_val = RUN_ALL_TESTS(); int ret_val = RUN_ALL_TESTS();
const char* const expected_events[] = { #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
"1st.OnTestProgramStart",
"2nd.OnTestProgramStart", // The deprecated OnTestSuiteStart/OnTestCaseStart events are included
"1st.OnTestIterationStart(0)", const char* const expected_events[] = {"1st.OnTestProgramStart",
"2nd.OnTestIterationStart(0)", "2nd.OnTestProgramStart",
"1st.OnEnvironmentsSetUpStart", "3rd.OnTestProgramStart",
"2nd.OnEnvironmentsSetUpStart", "1st.OnTestIterationStart(0)",
"Environment::SetUp", "2nd.OnTestIterationStart(0)",
"2nd.OnEnvironmentsSetUpEnd", "3rd.OnTestIterationStart(0)",
"1st.OnEnvironmentsSetUpEnd", "1st.OnEnvironmentsSetUpStart",
"1st.OnTestCaseStart", "2nd.OnEnvironmentsSetUpStart",
"2nd.OnTestCaseStart", "3rd.OnEnvironmentsSetUpStart",
"ListenerTest::SetUpTestCase", "Environment::SetUp",
"1st.OnTestStart", "3rd.OnEnvironmentsSetUpEnd",
"2nd.OnTestStart", "2nd.OnEnvironmentsSetUpEnd",
"ListenerTest::SetUp", "1st.OnEnvironmentsSetUpEnd",
"ListenerTest::* Test Body", "3rd.OnTestSuiteStart",
"1st.OnTestPartResult", "1st.OnTestCaseStart",
"2nd.OnTestPartResult", "2nd.OnTestCaseStart",
"ListenerTest::TearDown", "ListenerTest::SetUpTestSuite",
"2nd.OnTestEnd", "1st.OnTestStart",
"1st.OnTestEnd", "2nd.OnTestStart",
"1st.OnTestStart", "3rd.OnTestStart",
"2nd.OnTestStart", "ListenerTest::SetUp",
"ListenerTest::SetUp", "ListenerTest::* Test Body",
"ListenerTest::* Test Body", "1st.OnTestPartResult",
"1st.OnTestPartResult", "2nd.OnTestPartResult",
"2nd.OnTestPartResult", "3rd.OnTestPartResult",
"ListenerTest::TearDown", "ListenerTest::TearDown",
"2nd.OnTestEnd", "3rd.OnTestEnd",
"1st.OnTestEnd", "2nd.OnTestEnd",
"ListenerTest::TearDownTestCase", "1st.OnTestEnd",
"2nd.OnTestCaseEnd", "1st.OnTestStart",
"1st.OnTestCaseEnd", "2nd.OnTestStart",
"1st.OnEnvironmentsTearDownStart", "3rd.OnTestStart",
"2nd.OnEnvironmentsTearDownStart", "ListenerTest::SetUp",
"Environment::TearDown", "ListenerTest::* Test Body",
"2nd.OnEnvironmentsTearDownEnd", "1st.OnTestPartResult",
"1st.OnEnvironmentsTearDownEnd", "2nd.OnTestPartResult",
"2nd.OnTestIterationEnd(0)", "3rd.OnTestPartResult",
"1st.OnTestIterationEnd(0)", "ListenerTest::TearDown",
"1st.OnTestIterationStart(1)", "3rd.OnTestEnd",
"2nd.OnTestIterationStart(1)", "2nd.OnTestEnd",
"1st.OnEnvironmentsSetUpStart", "1st.OnTestEnd",
"2nd.OnEnvironmentsSetUpStart", "ListenerTest::TearDownTestSuite",
"Environment::SetUp", "3rd.OnTestSuiteEnd",
"2nd.OnEnvironmentsSetUpEnd", "2nd.OnTestCaseEnd",
"1st.OnEnvironmentsSetUpEnd", "1st.OnTestCaseEnd",
"1st.OnTestCaseStart", "1st.OnEnvironmentsTearDownStart",
"2nd.OnTestCaseStart", "2nd.OnEnvironmentsTearDownStart",
"ListenerTest::SetUpTestCase", "3rd.OnEnvironmentsTearDownStart",
"1st.OnTestStart", "Environment::TearDown",
"2nd.OnTestStart", "3rd.OnEnvironmentsTearDownEnd",
"ListenerTest::SetUp", "2nd.OnEnvironmentsTearDownEnd",
"ListenerTest::* Test Body", "1st.OnEnvironmentsTearDownEnd",
"1st.OnTestPartResult", "3rd.OnTestIterationEnd(0)",
"2nd.OnTestPartResult", "2nd.OnTestIterationEnd(0)",
"ListenerTest::TearDown", "1st.OnTestIterationEnd(0)",
"2nd.OnTestEnd", "1st.OnTestIterationStart(1)",
"1st.OnTestEnd", "2nd.OnTestIterationStart(1)",
"1st.OnTestStart", "3rd.OnTestIterationStart(1)",
"2nd.OnTestStart", "1st.OnEnvironmentsSetUpStart",
"ListenerTest::SetUp", "2nd.OnEnvironmentsSetUpStart",
"ListenerTest::* Test Body", "3rd.OnEnvironmentsSetUpStart",
"1st.OnTestPartResult", "Environment::SetUp",
"2nd.OnTestPartResult", "3rd.OnEnvironmentsSetUpEnd",
"ListenerTest::TearDown", "2nd.OnEnvironmentsSetUpEnd",
"2nd.OnTestEnd", "1st.OnEnvironmentsSetUpEnd",
"1st.OnTestEnd", "3rd.OnTestSuiteStart",
"ListenerTest::TearDownTestCase", "1st.OnTestCaseStart",
"2nd.OnTestCaseEnd", "2nd.OnTestCaseStart",
"1st.OnTestCaseEnd", "ListenerTest::SetUpTestSuite",
"1st.OnEnvironmentsTearDownStart", "1st.OnTestStart",
"2nd.OnEnvironmentsTearDownStart", "2nd.OnTestStart",
"Environment::TearDown", "3rd.OnTestStart",
"2nd.OnEnvironmentsTearDownEnd", "ListenerTest::SetUp",
"1st.OnEnvironmentsTearDownEnd", "ListenerTest::* Test Body",
"2nd.OnTestIterationEnd(1)", "1st.OnTestPartResult",
"1st.OnTestIterationEnd(1)", "2nd.OnTestPartResult",
"2nd.OnTestProgramEnd", "3rd.OnTestPartResult",
"1st.OnTestProgramEnd" "ListenerTest::TearDown",
}; "3rd.OnTestEnd",
"2nd.OnTestEnd",
"1st.OnTestEnd",
"1st.OnTestStart",
"2nd.OnTestStart",
"3rd.OnTestStart",
"ListenerTest::SetUp",
"ListenerTest::* Test Body",
"1st.OnTestPartResult",
"2nd.OnTestPartResult",
"3rd.OnTestPartResult",
"ListenerTest::TearDown",
"3rd.OnTestEnd",
"2nd.OnTestEnd",
"1st.OnTestEnd",
"ListenerTest::TearDownTestSuite",
"3rd.OnTestSuiteEnd",
"2nd.OnTestCaseEnd",
"1st.OnTestCaseEnd",
"1st.OnEnvironmentsTearDownStart",
"2nd.OnEnvironmentsTearDownStart",
"3rd.OnEnvironmentsTearDownStart",
"Environment::TearDown",
"3rd.OnEnvironmentsTearDownEnd",
"2nd.OnEnvironmentsTearDownEnd",
"1st.OnEnvironmentsTearDownEnd",
"3rd.OnTestIterationEnd(1)",
"2nd.OnTestIterationEnd(1)",
"1st.OnTestIterationEnd(1)",
"3rd.OnTestProgramEnd",
"2nd.OnTestProgramEnd",
"1st.OnTestProgramEnd"};
#else
const char* const expected_events[] = {"1st.OnTestProgramStart",
"2nd.OnTestProgramStart",
"3rd.OnTestProgramStart",
"1st.OnTestIterationStart(0)",
"2nd.OnTestIterationStart(0)",
"3rd.OnTestIterationStart(0)",
"1st.OnEnvironmentsSetUpStart",
"2nd.OnEnvironmentsSetUpStart",
"3rd.OnEnvironmentsSetUpStart",
"Environment::SetUp",
"3rd.OnEnvironmentsSetUpEnd",
"2nd.OnEnvironmentsSetUpEnd",
"1st.OnEnvironmentsSetUpEnd",
"3rd.OnTestSuiteStart",
"ListenerTest::SetUpTestSuite",
"1st.OnTestStart",
"2nd.OnTestStart",
"3rd.OnTestStart",
"ListenerTest::SetUp",
"ListenerTest::* Test Body",
"1st.OnTestPartResult",
"2nd.OnTestPartResult",
"3rd.OnTestPartResult",
"ListenerTest::TearDown",
"3rd.OnTestEnd",
"2nd.OnTestEnd",
"1st.OnTestEnd",
"1st.OnTestStart",
"2nd.OnTestStart",
"3rd.OnTestStart",
"ListenerTest::SetUp",
"ListenerTest::* Test Body",
"1st.OnTestPartResult",
"2nd.OnTestPartResult",
"3rd.OnTestPartResult",
"ListenerTest::TearDown",
"3rd.OnTestEnd",
"2nd.OnTestEnd",
"1st.OnTestEnd",
"ListenerTest::TearDownTestSuite",
"3rd.OnTestSuiteEnd",
"1st.OnEnvironmentsTearDownStart",
"2nd.OnEnvironmentsTearDownStart",
"3rd.OnEnvironmentsTearDownStart",
"Environment::TearDown",
"3rd.OnEnvironmentsTearDownEnd",
"2nd.OnEnvironmentsTearDownEnd",
"1st.OnEnvironmentsTearDownEnd",
"3rd.OnTestIterationEnd(0)",
"2nd.OnTestIterationEnd(0)",
"1st.OnTestIterationEnd(0)",
"1st.OnTestIterationStart(1)",
"2nd.OnTestIterationStart(1)",
"3rd.OnTestIterationStart(1)",
"1st.OnEnvironmentsSetUpStart",
"2nd.OnEnvironmentsSetUpStart",
"3rd.OnEnvironmentsSetUpStart",
"Environment::SetUp",
"3rd.OnEnvironmentsSetUpEnd",
"2nd.OnEnvironmentsSetUpEnd",
"1st.OnEnvironmentsSetUpEnd",
"3rd.OnTestSuiteStart",
"ListenerTest::SetUpTestSuite",
"1st.OnTestStart",
"2nd.OnTestStart",
"3rd.OnTestStart",
"ListenerTest::SetUp",
"ListenerTest::* Test Body",
"1st.OnTestPartResult",
"2nd.OnTestPartResult",
"3rd.OnTestPartResult",
"ListenerTest::TearDown",
"3rd.OnTestEnd",
"2nd.OnTestEnd",
"1st.OnTestEnd",
"1st.OnTestStart",
"2nd.OnTestStart",
"3rd.OnTestStart",
"ListenerTest::SetUp",
"ListenerTest::* Test Body",
"1st.OnTestPartResult",
"2nd.OnTestPartResult",
"3rd.OnTestPartResult",
"ListenerTest::TearDown",
"3rd.OnTestEnd",
"2nd.OnTestEnd",
"1st.OnTestEnd",
"ListenerTest::TearDownTestSuite",
"3rd.OnTestSuiteEnd",
"1st.OnEnvironmentsTearDownStart",
"2nd.OnEnvironmentsTearDownStart",
"3rd.OnEnvironmentsTearDownStart",
"Environment::TearDown",
"3rd.OnEnvironmentsTearDownEnd",
"2nd.OnEnvironmentsTearDownEnd",
"1st.OnEnvironmentsTearDownEnd",
"3rd.OnTestIterationEnd(1)",
"2nd.OnTestIterationEnd(1)",
"1st.OnTestIterationEnd(1)",
"3rd.OnTestProgramEnd",
"2nd.OnTestProgramEnd",
"1st.OnTestProgramEnd"};
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
VerifyResults(events, VerifyResults(events,
expected_events, expected_events,
sizeof(expected_events)/sizeof(expected_events[0])); sizeof(expected_events)/sizeof(expected_events[0]));
......
...@@ -111,7 +111,6 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) { ...@@ -111,7 +111,6 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
#elif GTEST_OS_FUCHSIA #elif GTEST_OS_FUCHSIA
const bool success = exe_str == "app"; const bool success = exe_str == "app";
#else #else
// FIXME: remove the hard-coded "lt-" prefix when libtool replacement is ready
const bool success = const bool success =
exe_str == "googletest-options-test" || exe_str == "googletest-options-test" ||
exe_str == "gtest_all_test" || exe_str == "gtest_all_test" ||
......
...@@ -12,7 +12,7 @@ Expected equality of these values: ...@@ -12,7 +12,7 @@ Expected equality of these values:
3 3
Stack trace: (omitted) Stack trace: (omitted)
[==========] Running 76 tests from 34 test cases. [==========] Running 85 tests from 40 test suites.
[----------] Global test environment set-up. [----------] Global test environment set-up.
FooEnvironment::SetUp() called. FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called. BarEnvironment::SetUp() called.
...@@ -380,66 +380,74 @@ Stack trace: (omitted) ...@@ -380,66 +380,74 @@ Stack trace: (omitted)
[ RUN ] AddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber [ RUN ] AddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
foo.cc:42: Failure foo.cc:42: Failure
Failed Failed
Expected failure in foo.cc Expected nonfatal failure in foo.cc
Stack trace: (omitted) Stack trace: (omitted)
[ FAILED ] AddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber [ FAILED ] AddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
[----------] 4 tests from MixedUpTestCaseTest [----------] 1 test from GtestFailAtTest
[ RUN ] MixedUpTestCaseTest.FirstTestFromNamespaceFoo [ RUN ] GtestFailAtTest.MessageContainsSpecifiedFileAndLineNumber
[ OK ] MixedUpTestCaseTest.FirstTestFromNamespaceFoo foo.cc:42: Failure
[ RUN ] MixedUpTestCaseTest.SecondTestFromNamespaceFoo Failed
[ OK ] MixedUpTestCaseTest.SecondTestFromNamespaceFoo Expected fatal failure in foo.cc
[ RUN ] MixedUpTestCaseTest.ThisShouldFail Stack trace: (omitted)
[ FAILED ] GtestFailAtTest.MessageContainsSpecifiedFileAndLineNumber
[----------] 4 tests from MixedUpTestSuiteTest
[ RUN ] MixedUpTestSuiteTest.FirstTestFromNamespaceFoo
[ OK ] MixedUpTestSuiteTest.FirstTestFromNamespaceFoo
[ RUN ] MixedUpTestSuiteTest.SecondTestFromNamespaceFoo
[ OK ] MixedUpTestSuiteTest.SecondTestFromNamespaceFoo
[ RUN ] MixedUpTestSuiteTest.ThisShouldFail
gtest.cc:#: Failure gtest.cc:#: Failure
Failed Failed
All tests in the same test case must use the same test fixture All tests in the same test suite must use the same test fixture
class. However, in test case MixedUpTestCaseTest, class. However, in test suite MixedUpTestSuiteTest,
you defined test FirstTestFromNamespaceFoo and test ThisShouldFail you defined test FirstTestFromNamespaceFoo and test ThisShouldFail
using two different test fixture classes. This can happen if using two different test fixture classes. This can happen if
the two classes are from different namespaces or translation the two classes are from different namespaces or translation
units and have the same name. You should probably rename one units and have the same name. You should probably rename one
of the classes to put the tests into different test cases. of the classes to put the tests into different test suites.
Stack trace: (omitted) Stack trace: (omitted)
[ FAILED ] MixedUpTestCaseTest.ThisShouldFail [ FAILED ] MixedUpTestSuiteTest.ThisShouldFail
[ RUN ] MixedUpTestCaseTest.ThisShouldFailToo [ RUN ] MixedUpTestSuiteTest.ThisShouldFailToo
gtest.cc:#: Failure gtest.cc:#: Failure
Failed Failed
All tests in the same test case must use the same test fixture All tests in the same test suite must use the same test fixture
class. However, in test case MixedUpTestCaseTest, class. However, in test suite MixedUpTestSuiteTest,
you defined test FirstTestFromNamespaceFoo and test ThisShouldFailToo you defined test FirstTestFromNamespaceFoo and test ThisShouldFailToo
using two different test fixture classes. This can happen if using two different test fixture classes. This can happen if
the two classes are from different namespaces or translation the two classes are from different namespaces or translation
units and have the same name. You should probably rename one units and have the same name. You should probably rename one
of the classes to put the tests into different test cases. of the classes to put the tests into different test suites.
Stack trace: (omitted) Stack trace: (omitted)
[ FAILED ] MixedUpTestCaseTest.ThisShouldFailToo [ FAILED ] MixedUpTestSuiteTest.ThisShouldFailToo
[----------] 2 tests from MixedUpTestCaseWithSameTestNameTest [----------] 2 tests from MixedUpTestSuiteWithSameTestNameTest
[ RUN ] MixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail [ RUN ] MixedUpTestSuiteWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
[ OK ] MixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail [ OK ] MixedUpTestSuiteWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
[ RUN ] MixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail [ RUN ] MixedUpTestSuiteWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
gtest.cc:#: Failure gtest.cc:#: Failure
Failed Failed
All tests in the same test case must use the same test fixture All tests in the same test suite must use the same test fixture
class. However, in test case MixedUpTestCaseWithSameTestNameTest, class. However, in test suite MixedUpTestSuiteWithSameTestNameTest,
you defined test TheSecondTestWithThisNameShouldFail and test TheSecondTestWithThisNameShouldFail you defined test TheSecondTestWithThisNameShouldFail and test TheSecondTestWithThisNameShouldFail
using two different test fixture classes. This can happen if using two different test fixture classes. This can happen if
the two classes are from different namespaces or translation the two classes are from different namespaces or translation
units and have the same name. You should probably rename one units and have the same name. You should probably rename one
of the classes to put the tests into different test cases. of the classes to put the tests into different test suites.
Stack trace: (omitted) Stack trace: (omitted)
[ FAILED ] MixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail [ FAILED ] MixedUpTestSuiteWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
[----------] 2 tests from TEST_F_before_TEST_in_same_test_case [----------] 2 tests from TEST_F_before_TEST_in_same_test_case
[ RUN ] TEST_F_before_TEST_in_same_test_case.DefinedUsingTEST_F [ RUN ] TEST_F_before_TEST_in_same_test_case.DefinedUsingTEST_F
[ OK ] TEST_F_before_TEST_in_same_test_case.DefinedUsingTEST_F [ OK ] TEST_F_before_TEST_in_same_test_case.DefinedUsingTEST_F
[ RUN ] TEST_F_before_TEST_in_same_test_case.DefinedUsingTESTAndShouldFail [ RUN ] TEST_F_before_TEST_in_same_test_case.DefinedUsingTESTAndShouldFail
gtest.cc:#: Failure gtest.cc:#: Failure
Failed Failed
All tests in the same test case must use the same test fixture All tests in the same test suite must use the same test fixture
class, so mixing TEST_F and TEST in the same test case is class, so mixing TEST_F and TEST in the same test suite is
illegal. In test case TEST_F_before_TEST_in_same_test_case, illegal. In test suite TEST_F_before_TEST_in_same_test_case,
test DefinedUsingTEST_F is defined using TEST_F but test DefinedUsingTEST_F is defined using TEST_F but
test DefinedUsingTESTAndShouldFail is defined using TEST. You probably test DefinedUsingTESTAndShouldFail is defined using TEST. You probably
want to change the TEST to TEST_F or move it to another test want to change the TEST to TEST_F or move it to another test
...@@ -453,9 +461,9 @@ Stack trace: (omitted) ...@@ -453,9 +461,9 @@ Stack trace: (omitted)
[ RUN ] TEST_before_TEST_F_in_same_test_case.DefinedUsingTEST_FAndShouldFail [ RUN ] TEST_before_TEST_F_in_same_test_case.DefinedUsingTEST_FAndShouldFail
gtest.cc:#: Failure gtest.cc:#: Failure
Failed Failed
All tests in the same test case must use the same test fixture All tests in the same test suite must use the same test fixture
class, so mixing TEST_F and TEST in the same test case is class, so mixing TEST_F and TEST in the same test suite is
illegal. In test case TEST_before_TEST_F_in_same_test_case, illegal. In test suite TEST_before_TEST_F_in_same_test_case,
test DefinedUsingTEST_FAndShouldFail is defined using TEST_F but test DefinedUsingTEST_FAndShouldFail is defined using TEST_F but
test DefinedUsingTEST is defined using TEST. You probably test DefinedUsingTEST is defined using TEST. You probably
want to change the TEST to TEST_F or move it to another test want to change the TEST to TEST_F or move it to another test
...@@ -870,6 +878,84 @@ Expected non-fatal failure. ...@@ -870,6 +878,84 @@ Expected non-fatal failure.
Stack trace: (omitted) Stack trace: (omitted)
[ FAILED ] ScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread [ FAILED ] ScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread
[----------] 2 tests from DynamicFixture
DynamicFixture::SetUpTestSuite
[ RUN ] DynamicFixture.DynamicTestPass
DynamicFixture()
DynamicFixture::SetUp
DynamicFixture::TearDown
~DynamicFixture()
[ OK ] DynamicFixture.DynamicTestPass
[ RUN ] DynamicFixture.DynamicTestFail
DynamicFixture()
DynamicFixture::SetUp
googletest-output-test_.cc:#: Failure
Value of: Pass
Actual: false
Expected: true
Stack trace: (omitted)
DynamicFixture::TearDown
~DynamicFixture()
[ FAILED ] DynamicFixture.DynamicTestFail
DynamicFixture::TearDownTestSuite
[----------] 1 test from DynamicFixtureAnotherName
DynamicFixture::SetUpTestSuite
[ RUN ] DynamicFixtureAnotherName.DynamicTestPass
DynamicFixture()
DynamicFixture::SetUp
DynamicFixture::TearDown
~DynamicFixture()
[ OK ] DynamicFixtureAnotherName.DynamicTestPass
DynamicFixture::TearDownTestSuite
[----------] 2 tests from BadDynamicFixture1
DynamicFixture::SetUpTestSuite
[ RUN ] BadDynamicFixture1.FixtureBase
DynamicFixture()
DynamicFixture::SetUp
DynamicFixture::TearDown
~DynamicFixture()
[ OK ] BadDynamicFixture1.FixtureBase
[ RUN ] BadDynamicFixture1.TestBase
DynamicFixture()
gtest.cc:#: Failure
Failed
All tests in the same test suite must use the same test fixture
class, so mixing TEST_F and TEST in the same test suite is
illegal. In test suite BadDynamicFixture1,
test FixtureBase is defined using TEST_F but
test TestBase is defined using TEST. You probably
want to change the TEST to TEST_F or move it to another test
case.
Stack trace: (omitted)
~DynamicFixture()
[ FAILED ] BadDynamicFixture1.TestBase
DynamicFixture::TearDownTestSuite
[----------] 2 tests from BadDynamicFixture2
DynamicFixture::SetUpTestSuite
[ RUN ] BadDynamicFixture2.FixtureBase
DynamicFixture()
DynamicFixture::SetUp
DynamicFixture::TearDown
~DynamicFixture()
[ OK ] BadDynamicFixture2.FixtureBase
[ RUN ] BadDynamicFixture2.Derived
DynamicFixture()
gtest.cc:#: Failure
Failed
All tests in the same test suite must use the same test fixture
class. However, in test suite BadDynamicFixture2,
you defined test FixtureBase and test Derived
using two different test fixture classes. This can happen if
the two classes are from different namespaces or translation
units and have the same name. You should probably rename one
of the classes to put the tests into different test suites.
Stack trace: (omitted)
~DynamicFixture()
[ FAILED ] BadDynamicFixture2.Derived
DynamicFixture::TearDownTestSuite
[----------] 1 test from PrintingFailingParams/FailingParamTest [----------] 1 test from PrintingFailingParams/FailingParamTest
[ RUN ] PrintingFailingParams/FailingParamTest.Fails/0 [ RUN ] PrintingFailingParams/FailingParamTest.Fails/0
googletest-output-test_.cc:#: Failure googletest-output-test_.cc:#: Failure
...@@ -880,6 +966,9 @@ Expected equality of these values: ...@@ -880,6 +966,9 @@ Expected equality of these values:
Stack trace: (omitted) Stack trace: (omitted)
[ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2 [ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
[----------] 1 test from EmptyBasenameParamInst
[ RUN ] EmptyBasenameParamInst.Passes/0
[ OK ] EmptyBasenameParamInst.Passes/0
[----------] 2 tests from PrintingStrings/ParamTest [----------] 2 tests from PrintingStrings/ParamTest
[ RUN ] PrintingStrings/ParamTest.Success/a [ RUN ] PrintingStrings/ParamTest.Success/a
[ OK ] PrintingStrings/ParamTest.Success/a [ OK ] PrintingStrings/ParamTest.Success/a
...@@ -906,9 +995,9 @@ Failed ...@@ -906,9 +995,9 @@ Failed
Expected fatal failure. Expected fatal failure.
Stack trace: (omitted) Stack trace: (omitted)
[==========] 76 tests from 34 test cases ran. [==========] 85 tests from 40 test suites ran.
[ PASSED ] 26 tests. [ PASSED ] 31 tests.
[ FAILED ] 50 tests, listed below: [ FAILED ] 54 tests, listed below:
[ FAILED ] NonfatalFailureTest.EscapesStringOperands [ FAILED ] NonfatalFailureTest.EscapesStringOperands
[ FAILED ] NonfatalFailureTest.DiffForLongStrings [ FAILED ] NonfatalFailureTest.DiffForLongStrings
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine [ FAILED ] FatalFailureTest.FatalFailureInSubroutine
...@@ -928,9 +1017,10 @@ Stack trace: (omitted) ...@@ -928,9 +1017,10 @@ Stack trace: (omitted)
[ FAILED ] NonFatalFailureInSetUpTest.FailureInSetUp [ FAILED ] NonFatalFailureInSetUpTest.FailureInSetUp
[ FAILED ] FatalFailureInSetUpTest.FailureInSetUp [ FAILED ] FatalFailureInSetUpTest.FailureInSetUp
[ FAILED ] AddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber [ FAILED ] AddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
[ FAILED ] MixedUpTestCaseTest.ThisShouldFail [ FAILED ] GtestFailAtTest.MessageContainsSpecifiedFileAndLineNumber
[ FAILED ] MixedUpTestCaseTest.ThisShouldFailToo [ FAILED ] MixedUpTestSuiteTest.ThisShouldFail
[ FAILED ] MixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail [ FAILED ] MixedUpTestSuiteTest.ThisShouldFailToo
[ FAILED ] MixedUpTestSuiteWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
[ FAILED ] TEST_F_before_TEST_in_same_test_case.DefinedUsingTESTAndShouldFail [ FAILED ] TEST_F_before_TEST_in_same_test_case.DefinedUsingTESTAndShouldFail
[ FAILED ] TEST_before_TEST_F_in_same_test_case.DefinedUsingTEST_FAndShouldFail [ FAILED ] TEST_before_TEST_F_in_same_test_case.DefinedUsingTEST_FAndShouldFail
[ FAILED ] ExpectNonfatalFailureTest.FailsWhenThereIsNoNonfatalFailure [ FAILED ] ExpectNonfatalFailureTest.FailsWhenThereIsNoNonfatalFailure
...@@ -957,14 +1047,17 @@ Stack trace: (omitted) ...@@ -957,14 +1047,17 @@ Stack trace: (omitted)
[ FAILED ] ExpectFailureWithThreadsTest.ExpectFatalFailure [ FAILED ] ExpectFailureWithThreadsTest.ExpectFatalFailure
[ FAILED ] ExpectFailureWithThreadsTest.ExpectNonFatalFailure [ FAILED ] ExpectFailureWithThreadsTest.ExpectNonFatalFailure
[ FAILED ] ScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread [ FAILED ] ScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread
[ FAILED ] DynamicFixture.DynamicTestFail
[ FAILED ] BadDynamicFixture1.TestBase
[ FAILED ] BadDynamicFixture2.Derived
[ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2 [ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
[ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a" [ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
50 FAILED TESTS 54 FAILED TESTS
 YOU HAVE 1 DISABLED TEST  YOU HAVE 1 DISABLED TEST
Note: Google Test filter = FatalFailureTest.*:LoggingTest.* Note: Google Test filter = FatalFailureTest.*:LoggingTest.*
[==========] Running 4 tests from 2 test cases. [==========] Running 4 tests from 2 test suites.
[----------] Global test environment set-up. [----------] Global test environment set-up.
[----------] 3 tests from FatalFailureTest [----------] 3 tests from FatalFailureTest
[ RUN ] FatalFailureTest.FatalFailureInSubroutine [ RUN ] FatalFailureTest.FatalFailureInSubroutine
...@@ -1017,7 +1110,7 @@ Stack trace: (omitted) ...@@ -1017,7 +1110,7 @@ Stack trace: (omitted)
[----------] 1 test from LoggingTest (? ms total) [----------] 1 test from LoggingTest (? ms total)
[----------] Global test environment tear-down [----------] Global test environment tear-down
[==========] 4 tests from 2 test cases ran. (? ms total) [==========] 4 tests from 2 test suites ran. (? ms total)
[ PASSED ] 0 tests. [ PASSED ] 0 tests.
[ FAILED ] 4 tests, listed below: [ FAILED ] 4 tests, listed below:
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine [ FAILED ] FatalFailureTest.FatalFailureInSubroutine
...@@ -1027,21 +1120,21 @@ Stack trace: (omitted) ...@@ -1027,21 +1120,21 @@ Stack trace: (omitted)
4 FAILED TESTS 4 FAILED TESTS
Note: Google Test filter = *DISABLED_* Note: Google Test filter = *DISABLED_*
[==========] Running 1 test from 1 test case. [==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up. [----------] Global test environment set-up.
[----------] 1 test from DisabledTestsWarningTest [----------] 1 test from DisabledTestsWarningTest
[ RUN ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning [ RUN ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
[ OK ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning [ OK ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
[----------] Global test environment tear-down [----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. [==========] 1 test from 1 test suite ran.
[ PASSED ] 1 test. [ PASSED ] 1 test.
Note: Google Test filter = PassingTest.* Note: Google Test filter = PassingTest.*
Note: This is test shard 2 of 2. Note: This is test shard 2 of 2.
[==========] Running 1 test from 1 test case. [==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up. [----------] Global test environment set-up.
[----------] 1 test from PassingTest [----------] 1 test from PassingTest
[ RUN ] PassingTest.PassingTest2 [ RUN ] PassingTest.PassingTest2
[ OK ] PassingTest.PassingTest2 [ OK ] PassingTest.PassingTest2
[----------] Global test environment tear-down [----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. [==========] 1 test from 1 test suite ran.
[ PASSED ] 1 test. [ PASSED ] 1 test.
...@@ -55,7 +55,6 @@ NO_STACKTRACE_SUPPORT_FLAG = '--no_stacktrace_support' ...@@ -55,7 +55,6 @@ NO_STACKTRACE_SUPPORT_FLAG = '--no_stacktrace_support'
IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux' IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
IS_WINDOWS = os.name == 'nt' IS_WINDOWS = os.name == 'nt'
# FIXME: remove the _lin suffix.
GOLDEN_NAME = 'googletest-output-test-golden-lin.txt' GOLDEN_NAME = 'googletest-output-test-golden-lin.txt'
PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('googletest-output-test_') PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('googletest-output-test_')
......
...@@ -92,9 +92,17 @@ TEST_P(FailingParamTest, Fails) { ...@@ -92,9 +92,17 @@ TEST_P(FailingParamTest, Fails) {
// This generates a test which will fail. Google Test is expected to print // This generates a test which will fail. Google Test is expected to print
// its parameter when it outputs the list of all failed tests. // its parameter when it outputs the list of all failed tests.
INSTANTIATE_TEST_CASE_P(PrintingFailingParams, INSTANTIATE_TEST_SUITE_P(PrintingFailingParams,
FailingParamTest, FailingParamTest,
testing::Values(2)); testing::Values(2));
// Tests that an empty value for the test suite basename yields just
// the test name without any prior /
class EmptyBasenameParamInst : public testing::TestWithParam<int> {};
TEST_P(EmptyBasenameParamInst, Passes) { EXPECT_EQ(1, GetParam()); }
INSTANTIATE_TEST_SUITE_P(, EmptyBasenameParamInst, testing::Values(1));
static const char kGoldenString[] = "\"Line\0 1\"\nLine 2"; static const char kGoldenString[] = "\"Line\0 1\"\nLine 2";
...@@ -461,7 +469,11 @@ TEST_F(FatalFailureInSetUpTest, FailureInSetUp) { ...@@ -461,7 +469,11 @@ TEST_F(FatalFailureInSetUpTest, FailureInSetUp) {
} }
TEST(AddFailureAtTest, MessageContainsSpecifiedFileAndLineNumber) { TEST(AddFailureAtTest, MessageContainsSpecifiedFileAndLineNumber) {
ADD_FAILURE_AT("foo.cc", 42) << "Expected failure in foo.cc"; ADD_FAILURE_AT("foo.cc", 42) << "Expected nonfatal failure in foo.cc";
}
TEST(GtestFailAtTest, MessageContainsSpecifiedFileAndLineNumber) {
GTEST_FAIL_AT("foo.cc", 42) << "Expected fatal failure in foo.cc";
} }
#if GTEST_IS_THREADSAFE #if GTEST_IS_THREADSAFE
...@@ -521,48 +533,48 @@ class DeathTestAndMultiThreadsTest : public testing::Test { ...@@ -521,48 +533,48 @@ class DeathTestAndMultiThreadsTest : public testing::Test {
#endif // GTEST_IS_THREADSAFE #endif // GTEST_IS_THREADSAFE
// The MixedUpTestCaseTest test case verifies that Google Test will fail a // The MixedUpTestSuiteTest test case verifies that Google Test will fail a
// test if it uses a different fixture class than what other tests in // test if it uses a different fixture class than what other tests in
// the same test case use. It deliberately contains two fixture // the same test case use. It deliberately contains two fixture
// classes with the same name but defined in different namespaces. // classes with the same name but defined in different namespaces.
// The MixedUpTestCaseWithSameTestNameTest test case verifies that // The MixedUpTestSuiteWithSameTestNameTest test case verifies that
// when the user defines two tests with the same test case name AND // when the user defines two tests with the same test case name AND
// same test name (but in different namespaces), the second test will // same test name (but in different namespaces), the second test will
// fail. // fail.
namespace foo { namespace foo {
class MixedUpTestCaseTest : public testing::Test { class MixedUpTestSuiteTest : public testing::Test {
}; };
TEST_F(MixedUpTestCaseTest, FirstTestFromNamespaceFoo) {} TEST_F(MixedUpTestSuiteTest, FirstTestFromNamespaceFoo) {}
TEST_F(MixedUpTestCaseTest, SecondTestFromNamespaceFoo) {} TEST_F(MixedUpTestSuiteTest, SecondTestFromNamespaceFoo) {}
class MixedUpTestCaseWithSameTestNameTest : public testing::Test { class MixedUpTestSuiteWithSameTestNameTest : public testing::Test {
}; };
TEST_F(MixedUpTestCaseWithSameTestNameTest, TEST_F(MixedUpTestSuiteWithSameTestNameTest,
TheSecondTestWithThisNameShouldFail) {} TheSecondTestWithThisNameShouldFail) {}
} // namespace foo } // namespace foo
namespace bar { namespace bar {
class MixedUpTestCaseTest : public testing::Test { class MixedUpTestSuiteTest : public testing::Test {
}; };
// The following two tests are expected to fail. We rely on the // The following two tests are expected to fail. We rely on the
// golden file to check that Google Test generates the right error message. // golden file to check that Google Test generates the right error message.
TEST_F(MixedUpTestCaseTest, ThisShouldFail) {} TEST_F(MixedUpTestSuiteTest, ThisShouldFail) {}
TEST_F(MixedUpTestCaseTest, ThisShouldFailToo) {} TEST_F(MixedUpTestSuiteTest, ThisShouldFailToo) {}
class MixedUpTestCaseWithSameTestNameTest : public testing::Test { class MixedUpTestSuiteWithSameTestNameTest : public testing::Test {
}; };
// Expected to fail. We rely on the golden file to check that Google Test // Expected to fail. We rely on the golden file to check that Google Test
// generates the right error message. // generates the right error message.
TEST_F(MixedUpTestCaseWithSameTestNameTest, TEST_F(MixedUpTestSuiteWithSameTestNameTest,
TheSecondTestWithThisNameShouldFail) {} TheSecondTestWithThisNameShouldFail) {}
} // namespace bar } // namespace bar
...@@ -773,10 +785,10 @@ TEST_P(ParamTest, Failure) { ...@@ -773,10 +785,10 @@ TEST_P(ParamTest, Failure) {
EXPECT_EQ("b", GetParam()) << "Expected failure"; EXPECT_EQ("b", GetParam()) << "Expected failure";
} }
INSTANTIATE_TEST_CASE_P(PrintingStrings, INSTANTIATE_TEST_SUITE_P(PrintingStrings,
ParamTest, ParamTest,
testing::Values(std::string("a")), testing::Values(std::string("a")),
ParamNameFunc); ParamNameFunc);
// This #ifdef block tests the output of typed tests. // This #ifdef block tests the output of typed tests.
#if GTEST_HAS_TYPED_TEST #if GTEST_HAS_TYPED_TEST
...@@ -785,7 +797,7 @@ template <typename T> ...@@ -785,7 +797,7 @@ template <typename T>
class TypedTest : public testing::Test { class TypedTest : public testing::Test {
}; };
TYPED_TEST_CASE(TypedTest, testing::Types<int>); TYPED_TEST_SUITE(TypedTest, testing::Types<int>);
TYPED_TEST(TypedTest, Success) { TYPED_TEST(TypedTest, Success) {
EXPECT_EQ(0, TypeParam()); EXPECT_EQ(0, TypeParam());
...@@ -804,14 +816,14 @@ class TypedTestNames { ...@@ -804,14 +816,14 @@ class TypedTestNames {
public: public:
template <typename T> template <typename T>
static std::string GetName(int i) { static std::string GetName(int i) {
if (testing::internal::IsSame<T, char>::value) if (std::is_same<T, char>::value)
return std::string("char") + ::testing::PrintToString(i); return std::string("char") + ::testing::PrintToString(i);
if (testing::internal::IsSame<T, int>::value) if (std::is_same<T, int>::value)
return std::string("int") + ::testing::PrintToString(i); return std::string("int") + ::testing::PrintToString(i);
} }
}; };
TYPED_TEST_CASE(TypedTestWithNames, TypesForTestWithNames, TypedTestNames); TYPED_TEST_SUITE(TypedTestWithNames, TypesForTestWithNames, TypedTestNames);
TYPED_TEST(TypedTestWithNames, Success) {} TYPED_TEST(TypedTestWithNames, Success) {}
...@@ -826,7 +838,7 @@ template <typename T> ...@@ -826,7 +838,7 @@ template <typename T>
class TypedTestP : public testing::Test { class TypedTestP : public testing::Test {
}; };
TYPED_TEST_CASE_P(TypedTestP); TYPED_TEST_SUITE_P(TypedTestP);
TYPED_TEST_P(TypedTestP, Success) { TYPED_TEST_P(TypedTestP, Success) {
EXPECT_EQ(0U, TypeParam()); EXPECT_EQ(0U, TypeParam());
...@@ -836,25 +848,25 @@ TYPED_TEST_P(TypedTestP, Failure) { ...@@ -836,25 +848,25 @@ TYPED_TEST_P(TypedTestP, Failure) {
EXPECT_EQ(1U, TypeParam()) << "Expected failure"; EXPECT_EQ(1U, TypeParam()) << "Expected failure";
} }
REGISTER_TYPED_TEST_CASE_P(TypedTestP, Success, Failure); REGISTER_TYPED_TEST_SUITE_P(TypedTestP, Success, Failure);
typedef testing::Types<unsigned char, unsigned int> UnsignedTypes; typedef testing::Types<unsigned char, unsigned int> UnsignedTypes;
INSTANTIATE_TYPED_TEST_CASE_P(Unsigned, TypedTestP, UnsignedTypes); INSTANTIATE_TYPED_TEST_SUITE_P(Unsigned, TypedTestP, UnsignedTypes);
class TypedTestPNames { class TypedTestPNames {
public: public:
template <typename T> template <typename T>
static std::string GetName(int i) { static std::string GetName(int i) {
if (testing::internal::IsSame<T, unsigned char>::value) { if (std::is_same<T, unsigned char>::value) {
return std::string("unsignedChar") + ::testing::PrintToString(i); return std::string("unsignedChar") + ::testing::PrintToString(i);
} }
if (testing::internal::IsSame<T, unsigned int>::value) { if (std::is_same<T, unsigned int>::value) {
return std::string("unsignedInt") + ::testing::PrintToString(i); return std::string("unsignedInt") + ::testing::PrintToString(i);
} }
} }
}; };
INSTANTIATE_TYPED_TEST_CASE_P(UnsignedCustomName, TypedTestP, UnsignedTypes, INSTANTIATE_TYPED_TEST_SUITE_P(UnsignedCustomName, TypedTestP, UnsignedTypes,
TypedTestPNames); TypedTestPNames);
#endif // GTEST_HAS_TYPED_TEST_P #endif // GTEST_HAS_TYPED_TEST_P
...@@ -877,7 +889,7 @@ class ATypedDeathTest : public testing::Test { ...@@ -877,7 +889,7 @@ class ATypedDeathTest : public testing::Test {
}; };
typedef testing::Types<int, double> NumericTypes; typedef testing::Types<int, double> NumericTypes;
TYPED_TEST_CASE(ATypedDeathTest, NumericTypes); TYPED_TEST_SUITE(ATypedDeathTest, NumericTypes);
TYPED_TEST(ATypedDeathTest, ShouldRunFirst) { TYPED_TEST(ATypedDeathTest, ShouldRunFirst) {
} }
...@@ -894,14 +906,14 @@ template <typename T> ...@@ -894,14 +906,14 @@ template <typename T>
class ATypeParamDeathTest : public testing::Test { class ATypeParamDeathTest : public testing::Test {
}; };
TYPED_TEST_CASE_P(ATypeParamDeathTest); TYPED_TEST_SUITE_P(ATypeParamDeathTest);
TYPED_TEST_P(ATypeParamDeathTest, ShouldRunFirst) { TYPED_TEST_P(ATypeParamDeathTest, ShouldRunFirst) {
} }
REGISTER_TYPED_TEST_CASE_P(ATypeParamDeathTest, ShouldRunFirst); REGISTER_TYPED_TEST_SUITE_P(ATypeParamDeathTest, ShouldRunFirst);
INSTANTIATE_TYPED_TEST_CASE_P(My, ATypeParamDeathTest, NumericTypes); INSTANTIATE_TYPED_TEST_SUITE_P(My, ATypeParamDeathTest, NumericTypes);
# endif // GTEST_HAS_TYPED_TEST_P # endif // GTEST_HAS_TYPED_TEST_P
...@@ -1024,6 +1036,56 @@ TEST_F(ExpectFailureTest, ExpectNonFatalFailureOnAllThreads) { ...@@ -1024,6 +1036,56 @@ TEST_F(ExpectFailureTest, ExpectNonFatalFailureOnAllThreads) {
"Some other non-fatal failure."); "Some other non-fatal failure.");
} }
class DynamicFixture : public testing::Test {
protected:
DynamicFixture() { printf("DynamicFixture()\n"); }
~DynamicFixture() override { printf("~DynamicFixture()\n"); }
void SetUp() override { printf("DynamicFixture::SetUp\n"); }
void TearDown() override { printf("DynamicFixture::TearDown\n"); }
static void SetUpTestSuite() { printf("DynamicFixture::SetUpTestSuite\n"); }
static void TearDownTestSuite() {
printf("DynamicFixture::TearDownTestSuite\n");
}
};
template <bool Pass>
class DynamicTest : public DynamicFixture {
public:
void TestBody() override { EXPECT_TRUE(Pass); }
};
auto dynamic_test = (
// Register two tests with the same fixture correctly.
testing::RegisterTest(
"DynamicFixture", "DynamicTestPass", nullptr, nullptr, __FILE__,
__LINE__, []() -> DynamicFixture* { return new DynamicTest<true>; }),
testing::RegisterTest(
"DynamicFixture", "DynamicTestFail", nullptr, nullptr, __FILE__,
__LINE__, []() -> DynamicFixture* { return new DynamicTest<false>; }),
// Register the same fixture with another name. That's fine.
testing::RegisterTest(
"DynamicFixtureAnotherName", "DynamicTestPass", nullptr, nullptr,
__FILE__, __LINE__,
[]() -> DynamicFixture* { return new DynamicTest<true>; }),
// Register two tests with the same fixture incorrectly.
testing::RegisterTest(
"BadDynamicFixture1", "FixtureBase", nullptr, nullptr, __FILE__,
__LINE__, []() -> DynamicFixture* { return new DynamicTest<true>; }),
testing::RegisterTest(
"BadDynamicFixture1", "TestBase", nullptr, nullptr, __FILE__, __LINE__,
[]() -> testing::Test* { return new DynamicTest<true>; }),
// Register two tests with the same fixture incorrectly by ommiting the
// return type.
testing::RegisterTest(
"BadDynamicFixture2", "FixtureBase", nullptr, nullptr, __FILE__,
__LINE__, []() -> DynamicFixture* { return new DynamicTest<true>; }),
testing::RegisterTest("BadDynamicFixture2", "Derived", nullptr, nullptr,
__FILE__, __LINE__,
[]() { return new DynamicTest<true>; }));
// Two test environments for testing testing::AddGlobalTestEnvironment(). // Two test environments for testing testing::AddGlobalTestEnvironment().
......
...@@ -36,10 +36,10 @@ class DummyTest : public ::testing::TestWithParam<const char *> {}; ...@@ -36,10 +36,10 @@ class DummyTest : public ::testing::TestWithParam<const char *> {};
TEST_P(DummyTest, Dummy) { TEST_P(DummyTest, Dummy) {
} }
INSTANTIATE_TEST_CASE_P(InvalidTestName, INSTANTIATE_TEST_SUITE_P(InvalidTestName,
DummyTest, DummyTest,
::testing::Values("InvalidWithQuotes"), ::testing::Values("InvalidWithQuotes"),
::testing::PrintToStringParamName()); ::testing::PrintToStringParamName());
} // namespace } // namespace
......
...@@ -41,10 +41,10 @@ std::string StringParamTestSuffix( ...@@ -41,10 +41,10 @@ std::string StringParamTestSuffix(
TEST_P(DummyTest, Dummy) { TEST_P(DummyTest, Dummy) {
} }
INSTANTIATE_TEST_CASE_P(DuplicateTestNames, INSTANTIATE_TEST_SUITE_P(DuplicateTestNames,
DummyTest, DummyTest,
::testing::Values("a", "b", "a", "c"), ::testing::Values("a", "b", "a", "c"),
StringParamTestSuffix); StringParamTestSuffix);
} // namespace } // namespace
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
......
...@@ -542,12 +542,12 @@ TEST(ParamGeneratorTest, AssignmentWorks) { ...@@ -542,12 +542,12 @@ TEST(ParamGeneratorTest, AssignmentWorks) {
// This test verifies that the tests are expanded and run as specified: // This test verifies that the tests are expanded and run as specified:
// one test per element from the sequence produced by the generator // one test per element from the sequence produced by the generator
// specified in INSTANTIATE_TEST_CASE_P. It also verifies that the test's // specified in INSTANTIATE_TEST_SUITE_P. It also verifies that the test's
// fixture constructor, SetUp(), and TearDown() have run and have been // fixture constructor, SetUp(), and TearDown() have run and have been
// supplied with the correct parameters. // supplied with the correct parameters.
// The use of environment object allows detection of the case where no test // The use of environment object allows detection of the case where no test
// case functionality is run at all. In this case TestCaseTearDown will not // case functionality is run at all. In this case TearDownTestSuite will not
// be able to detect missing tests, naturally. // be able to detect missing tests, naturally.
template <int kExpectedCalls> template <int kExpectedCalls>
class TestGenerationEnvironment : public ::testing::Environment { class TestGenerationEnvironment : public ::testing::Environment {
...@@ -628,7 +628,7 @@ class TestGenerationTest : public TestWithParam<int> { ...@@ -628,7 +628,7 @@ class TestGenerationTest : public TestWithParam<int> {
EXPECT_EQ(current_parameter_, GetParam()); EXPECT_EQ(current_parameter_, GetParam());
} }
static void SetUpTestCase() { static void SetUpTestSuite() {
bool all_tests_in_test_case_selected = true; bool all_tests_in_test_case_selected = true;
for (int i = 0; i < PARAMETER_COUNT; ++i) { for (int i = 0; i < PARAMETER_COUNT; ++i) {
...@@ -649,7 +649,7 @@ class TestGenerationTest : public TestWithParam<int> { ...@@ -649,7 +649,7 @@ class TestGenerationTest : public TestWithParam<int> {
collected_parameters_.clear(); collected_parameters_.clear();
} }
static void TearDownTestCase() { static void TearDownTestSuite() {
vector<int> expected_values(test_generation_params, vector<int> expected_values(test_generation_params,
test_generation_params + PARAMETER_COUNT); test_generation_params + PARAMETER_COUNT);
// Test execution order is not guaranteed by Google Test, // Test execution order is not guaranteed by Google Test,
...@@ -675,17 +675,17 @@ TEST_P(TestGenerationTest, TestsExpandedAndRun) { ...@@ -675,17 +675,17 @@ TEST_P(TestGenerationTest, TestsExpandedAndRun) {
EXPECT_EQ(current_parameter_, GetParam()); EXPECT_EQ(current_parameter_, GetParam());
collected_parameters_.push_back(GetParam()); collected_parameters_.push_back(GetParam());
} }
INSTANTIATE_TEST_CASE_P(TestExpansionModule, TestGenerationTest, INSTANTIATE_TEST_SUITE_P(TestExpansionModule, TestGenerationTest,
ValuesIn(test_generation_params)); ValuesIn(test_generation_params));
// This test verifies that the element sequence (third parameter of // This test verifies that the element sequence (third parameter of
// INSTANTIATE_TEST_CASE_P) is evaluated in InitGoogleTest() and neither at // INSTANTIATE_TEST_SUITE_P) is evaluated in InitGoogleTest() and neither at
// the call site of INSTANTIATE_TEST_CASE_P nor in RUN_ALL_TESTS(). For // the call site of INSTANTIATE_TEST_SUITE_P nor in RUN_ALL_TESTS(). For
// that, we declare param_value_ to be a static member of // that, we declare param_value_ to be a static member of
// GeneratorEvaluationTest and initialize it to 0. We set it to 1 in // GeneratorEvaluationTest and initialize it to 0. We set it to 1 in
// main(), just before invocation of InitGoogleTest(). After calling // main(), just before invocation of InitGoogleTest(). After calling
// InitGoogleTest(), we set the value to 2. If the sequence is evaluated // InitGoogleTest(), we set the value to 2. If the sequence is evaluated
// before or after InitGoogleTest, INSTANTIATE_TEST_CASE_P will create a // before or after InitGoogleTest, INSTANTIATE_TEST_SUITE_P will create a
// test with parameter other than 1, and the test body will fail the // test with parameter other than 1, and the test body will fail the
// assertion. // assertion.
class GeneratorEvaluationTest : public TestWithParam<int> { class GeneratorEvaluationTest : public TestWithParam<int> {
...@@ -701,9 +701,8 @@ int GeneratorEvaluationTest::param_value_ = 0; ...@@ -701,9 +701,8 @@ int GeneratorEvaluationTest::param_value_ = 0;
TEST_P(GeneratorEvaluationTest, GeneratorsEvaluatedInMain) { TEST_P(GeneratorEvaluationTest, GeneratorsEvaluatedInMain) {
EXPECT_EQ(1, GetParam()); EXPECT_EQ(1, GetParam());
} }
INSTANTIATE_TEST_CASE_P(GenEvalModule, INSTANTIATE_TEST_SUITE_P(GenEvalModule, GeneratorEvaluationTest,
GeneratorEvaluationTest, Values(GeneratorEvaluationTest::param_value()));
Values(GeneratorEvaluationTest::param_value()));
// Tests that generators defined in a different translation unit are // Tests that generators defined in a different translation unit are
// functional. Generator extern_gen is defined in gtest-param-test_test2.cc. // functional. Generator extern_gen is defined in gtest-param-test_test2.cc.
...@@ -714,9 +713,8 @@ TEST_P(ExternalGeneratorTest, ExternalGenerator) { ...@@ -714,9 +713,8 @@ TEST_P(ExternalGeneratorTest, ExternalGenerator) {
// which we verify here. // which we verify here.
EXPECT_EQ(GetParam(), 33); EXPECT_EQ(GetParam(), 33);
} }
INSTANTIATE_TEST_CASE_P(ExternalGeneratorModule, INSTANTIATE_TEST_SUITE_P(ExternalGeneratorModule, ExternalGeneratorTest,
ExternalGeneratorTest, extern_gen);
extern_gen);
// Tests that a parameterized test case can be defined in one translation // Tests that a parameterized test case can be defined in one translation
// unit and instantiated in another. This test will be instantiated in // unit and instantiated in another. This test will be instantiated in
...@@ -731,20 +729,19 @@ TEST_P(ExternalInstantiationTest, IsMultipleOf33) { ...@@ -731,20 +729,19 @@ TEST_P(ExternalInstantiationTest, IsMultipleOf33) {
class MultipleInstantiationTest : public TestWithParam<int> {}; class MultipleInstantiationTest : public TestWithParam<int> {};
TEST_P(MultipleInstantiationTest, AllowsMultipleInstances) { TEST_P(MultipleInstantiationTest, AllowsMultipleInstances) {
} }
INSTANTIATE_TEST_CASE_P(Sequence1, MultipleInstantiationTest, Values(1, 2)); INSTANTIATE_TEST_SUITE_P(Sequence1, MultipleInstantiationTest, Values(1, 2));
INSTANTIATE_TEST_CASE_P(Sequence2, MultipleInstantiationTest, Range(3, 5)); INSTANTIATE_TEST_SUITE_P(Sequence2, MultipleInstantiationTest, Range(3, 5));
// Tests that a parameterized test case can be instantiated // Tests that a parameterized test case can be instantiated
// in multiple translation units. This test will be instantiated // in multiple translation units. This test will be instantiated
// here and in gtest-param-test_test2.cc. // here and in gtest-param-test_test2.cc.
// InstantiationInMultipleTranslationUnitsTest fixture class // InstantiationInMultipleTranslationUnitsTest fixture class
// is defined in gtest-param-test_test.h. // is defined in gtest-param-test_test.h.
TEST_P(InstantiationInMultipleTranslaionUnitsTest, IsMultipleOf42) { TEST_P(InstantiationInMultipleTranslationUnitsTest, IsMultipleOf42) {
EXPECT_EQ(0, GetParam() % 42); EXPECT_EQ(0, GetParam() % 42);
} }
INSTANTIATE_TEST_CASE_P(Sequence1, INSTANTIATE_TEST_SUITE_P(Sequence1, InstantiationInMultipleTranslationUnitsTest,
InstantiationInMultipleTranslaionUnitsTest, Values(42, 42 * 2));
Values(42, 42*2));
// Tests that each iteration of parameterized test runs in a separate test // Tests that each iteration of parameterized test runs in a separate test
// object. // object.
...@@ -752,7 +749,7 @@ class SeparateInstanceTest : public TestWithParam<int> { ...@@ -752,7 +749,7 @@ class SeparateInstanceTest : public TestWithParam<int> {
public: public:
SeparateInstanceTest() : count_(0) {} SeparateInstanceTest() : count_(0) {}
static void TearDownTestCase() { static void TearDownTestSuite() {
EXPECT_GE(global_count_, 2) EXPECT_GE(global_count_, 2)
<< "If some (but not all) SeparateInstanceTest tests have been " << "If some (but not all) SeparateInstanceTest tests have been "
<< "filtered out this test will fail. Make sure that all " << "filtered out this test will fail. Make sure that all "
...@@ -770,20 +767,20 @@ TEST_P(SeparateInstanceTest, TestsRunInSeparateInstances) { ...@@ -770,20 +767,20 @@ TEST_P(SeparateInstanceTest, TestsRunInSeparateInstances) {
EXPECT_EQ(0, count_++); EXPECT_EQ(0, count_++);
global_count_++; global_count_++;
} }
INSTANTIATE_TEST_CASE_P(FourElemSequence, SeparateInstanceTest, Range(1, 4)); INSTANTIATE_TEST_SUITE_P(FourElemSequence, SeparateInstanceTest, Range(1, 4));
// Tests that all instantiations of a test have named appropriately. Test // Tests that all instantiations of a test have named appropriately. Test
// defined with TEST_P(TestCaseName, TestName) and instantiated with // defined with TEST_P(TestSuiteName, TestName) and instantiated with
// INSTANTIATE_TEST_CASE_P(SequenceName, TestCaseName, generator) must be named // INSTANTIATE_TEST_SUITE_P(SequenceName, TestSuiteName, generator) must be
// SequenceName/TestCaseName.TestName/i, where i is the 0-based index of the // named SequenceName/TestSuiteName.TestName/i, where i is the 0-based index of
// sequence element used to instantiate the test. // the sequence element used to instantiate the test.
class NamingTest : public TestWithParam<int> {}; class NamingTest : public TestWithParam<int> {};
TEST_P(NamingTest, TestsReportCorrectNamesAndParameters) { TEST_P(NamingTest, TestsReportCorrectNamesAndParameters) {
const ::testing::TestInfo* const test_info = const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info(); ::testing::UnitTest::GetInstance()->current_test_info();
EXPECT_STREQ("ZeroToFiveSequence/NamingTest", test_info->test_case_name()); EXPECT_STREQ("ZeroToFiveSequence/NamingTest", test_info->test_suite_name());
Message index_stream; Message index_stream;
index_stream << "TestsReportCorrectNamesAndParameters/" << GetParam(); index_stream << "TestsReportCorrectNamesAndParameters/" << GetParam();
...@@ -792,7 +789,7 @@ TEST_P(NamingTest, TestsReportCorrectNamesAndParameters) { ...@@ -792,7 +789,7 @@ TEST_P(NamingTest, TestsReportCorrectNamesAndParameters) {
EXPECT_EQ(::testing::PrintToString(GetParam()), test_info->value_param()); EXPECT_EQ(::testing::PrintToString(GetParam()), test_info->value_param());
} }
INSTANTIATE_TEST_CASE_P(ZeroToFiveSequence, NamingTest, Range(0, 5)); INSTANTIATE_TEST_SUITE_P(ZeroToFiveSequence, NamingTest, Range(0, 5));
// Tests that macros in test names are expanded correctly. // Tests that macros in test names are expanded correctly.
class MacroNamingTest : public TestWithParam<int> {}; class MacroNamingTest : public TestWithParam<int> {};
...@@ -804,11 +801,11 @@ TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) { ...@@ -804,11 +801,11 @@ TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) {
const ::testing::TestInfo* const test_info = const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info(); ::testing::UnitTest::GetInstance()->current_test_info();
EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_case_name()); EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_suite_name());
EXPECT_STREQ("FooSomeTestName", test_info->name()); EXPECT_STREQ("FooSomeTestName", test_info->name());
} }
INSTANTIATE_TEST_CASE_P(FortyTwo, MacroNamingTest, Values(42)); INSTANTIATE_TEST_SUITE_P(FortyTwo, MacroNamingTest, Values(42));
// Tests the same thing for non-parametrized tests. // Tests the same thing for non-parametrized tests.
class MacroNamingTestNonParametrized : public ::testing::Test {}; class MacroNamingTestNonParametrized : public ::testing::Test {};
...@@ -818,7 +815,7 @@ TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized), ...@@ -818,7 +815,7 @@ TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized),
const ::testing::TestInfo* const test_info = const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info(); ::testing::UnitTest::GetInstance()->current_test_info();
EXPECT_STREQ("MacroNamingTestNonParametrized", test_info->test_case_name()); EXPECT_STREQ("MacroNamingTestNonParametrized", test_info->test_suite_name());
EXPECT_STREQ("FooSomeTestName", test_info->name()); EXPECT_STREQ("FooSomeTestName", test_info->name());
} }
...@@ -835,17 +832,14 @@ struct CustomParamNameFunctor { ...@@ -835,17 +832,14 @@ struct CustomParamNameFunctor {
} }
}; };
INSTANTIATE_TEST_CASE_P(CustomParamNameFunctor, INSTANTIATE_TEST_SUITE_P(CustomParamNameFunctor, CustomFunctorNamingTest,
CustomFunctorNamingTest, Values(std::string("FunctorName")),
Values(std::string("FunctorName")), CustomParamNameFunctor());
CustomParamNameFunctor());
INSTANTIATE_TEST_CASE_P(AllAllowedCharacters, INSTANTIATE_TEST_SUITE_P(AllAllowedCharacters, CustomFunctorNamingTest,
CustomFunctorNamingTest, Values("abcdefghijklmnopqrstuvwxyz",
Values("abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "01234567890_"),
"ABCDEFGHIJKLMNOPQRSTUVWXYZ", CustomParamNameFunctor());
"01234567890_"),
CustomParamNameFunctor());
inline std::string CustomParamNameFunction( inline std::string CustomParamNameFunction(
const ::testing::TestParamInfo<std::string>& inf) { const ::testing::TestParamInfo<std::string>& inf) {
...@@ -855,38 +849,40 @@ inline std::string CustomParamNameFunction( ...@@ -855,38 +849,40 @@ inline std::string CustomParamNameFunction(
class CustomFunctionNamingTest : public TestWithParam<std::string> {}; class CustomFunctionNamingTest : public TestWithParam<std::string> {};
TEST_P(CustomFunctionNamingTest, CustomTestNames) {} TEST_P(CustomFunctionNamingTest, CustomTestNames) {}
INSTANTIATE_TEST_CASE_P(CustomParamNameFunction, INSTANTIATE_TEST_SUITE_P(CustomParamNameFunction, CustomFunctionNamingTest,
CustomFunctionNamingTest, Values(std::string("FunctionName")),
Values(std::string("FunctionName")), CustomParamNameFunction);
CustomParamNameFunction);
INSTANTIATE_TEST_SUITE_P(CustomParamNameFunctionP, CustomFunctionNamingTest,
Values(std::string("FunctionNameP")),
&CustomParamNameFunction);
// Test custom naming with a lambda // Test custom naming with a lambda
class CustomLambdaNamingTest : public TestWithParam<std::string> {}; class CustomLambdaNamingTest : public TestWithParam<std::string> {};
TEST_P(CustomLambdaNamingTest, CustomTestNames) {} TEST_P(CustomLambdaNamingTest, CustomTestNames) {}
INSTANTIATE_TEST_CASE_P(CustomParamNameLambda, CustomLambdaNamingTest, INSTANTIATE_TEST_SUITE_P(CustomParamNameLambda, CustomLambdaNamingTest,
Values(std::string("LambdaName")), Values(std::string("LambdaName")),
[](const ::testing::TestParamInfo<std::string>& inf) { [](const ::testing::TestParamInfo<std::string>& inf) {
return inf.param; return inf.param;
}); });
TEST(CustomNamingTest, CheckNameRegistry) { TEST(CustomNamingTest, CheckNameRegistry) {
::testing::UnitTest* unit_test = ::testing::UnitTest::GetInstance(); ::testing::UnitTest* unit_test = ::testing::UnitTest::GetInstance();
std::set<std::string> test_names; std::set<std::string> test_names;
for (int case_num = 0; for (int suite_num = 0; suite_num < unit_test->total_test_suite_count();
case_num < unit_test->total_test_case_count(); ++suite_num) {
++case_num) { const ::testing::TestSuite* test_suite = unit_test->GetTestSuite(suite_num);
const ::testing::TestCase* test_case = unit_test->GetTestCase(case_num); for (int test_num = 0; test_num < test_suite->total_test_count();
for (int test_num = 0;
test_num < test_case->total_test_count();
++test_num) { ++test_num) {
const ::testing::TestInfo* test_info = test_case->GetTestInfo(test_num); const ::testing::TestInfo* test_info = test_suite->GetTestInfo(test_num);
test_names.insert(std::string(test_info->name())); test_names.insert(std::string(test_info->name()));
} }
} }
EXPECT_EQ(1u, test_names.count("CustomTestNames/FunctorName")); EXPECT_EQ(1u, test_names.count("CustomTestNames/FunctorName"));
EXPECT_EQ(1u, test_names.count("CustomTestNames/FunctionName")); EXPECT_EQ(1u, test_names.count("CustomTestNames/FunctionName"));
EXPECT_EQ(1u, test_names.count("CustomTestNames/FunctionNameP"));
EXPECT_EQ(1u, test_names.count("CustomTestNames/LambdaName")); EXPECT_EQ(1u, test_names.count("CustomTestNames/LambdaName"));
} }
...@@ -902,10 +898,8 @@ TEST_P(CustomIntegerNamingTest, TestsReportCorrectNames) { ...@@ -902,10 +898,8 @@ TEST_P(CustomIntegerNamingTest, TestsReportCorrectNames) {
EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name()); EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
} }
INSTANTIATE_TEST_CASE_P(PrintToString, INSTANTIATE_TEST_SUITE_P(PrintToString, CustomIntegerNamingTest, Range(0, 5),
CustomIntegerNamingTest, ::testing::PrintToStringParamName());
Range(0, 5),
::testing::PrintToStringParamName());
// Test a custom struct with PrintToString. // Test a custom struct with PrintToString.
...@@ -929,10 +923,9 @@ TEST_P(CustomStructNamingTest, TestsReportCorrectNames) { ...@@ -929,10 +923,9 @@ TEST_P(CustomStructNamingTest, TestsReportCorrectNames) {
EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name()); EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
} }
INSTANTIATE_TEST_CASE_P(PrintToString, INSTANTIATE_TEST_SUITE_P(PrintToString, CustomStructNamingTest,
CustomStructNamingTest, Values(CustomStruct(0), CustomStruct(1)),
Values(CustomStruct(0), CustomStruct(1)), ::testing::PrintToStringParamName());
::testing::PrintToStringParamName());
// Test that using a stateful parameter naming function works as expected. // Test that using a stateful parameter naming function works as expected.
...@@ -961,10 +954,8 @@ TEST_P(StatefulNamingTest, TestsReportCorrectNames) { ...@@ -961,10 +954,8 @@ TEST_P(StatefulNamingTest, TestsReportCorrectNames) {
EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name()); EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
} }
INSTANTIATE_TEST_CASE_P(StatefulNamingFunctor, INSTANTIATE_TEST_SUITE_P(StatefulNamingFunctor, StatefulNamingTest, Range(0, 5),
StatefulNamingTest, StatefulNamingFunctor());
Range(0, 5),
StatefulNamingFunctor());
// Class that cannot be streamed into an ostream. It needs to be copyable // Class that cannot be streamed into an ostream. It needs to be copyable
// (and, in case of MSVC, also assignable) in order to be a test parameter // (and, in case of MSVC, also assignable) in order to be a test parameter
...@@ -973,6 +964,8 @@ INSTANTIATE_TEST_CASE_P(StatefulNamingFunctor, ...@@ -973,6 +964,8 @@ INSTANTIATE_TEST_CASE_P(StatefulNamingFunctor,
class Unstreamable { class Unstreamable {
public: public:
explicit Unstreamable(int value) : value_(value) {} explicit Unstreamable(int value) : value_(value) {}
// -Wunused-private-field: dummy accessor for `value_`.
const int& dummy_value() const { return value_; }
private: private:
int value_; int value_;
...@@ -987,9 +980,8 @@ TEST_P(CommentTest, TestsCorrectlyReportUnstreamableParams) { ...@@ -987,9 +980,8 @@ TEST_P(CommentTest, TestsCorrectlyReportUnstreamableParams) {
EXPECT_EQ(::testing::PrintToString(GetParam()), test_info->value_param()); EXPECT_EQ(::testing::PrintToString(GetParam()), test_info->value_param());
} }
INSTANTIATE_TEST_CASE_P(InstantiationWithComments, INSTANTIATE_TEST_SUITE_P(InstantiationWithComments, CommentTest,
CommentTest, Values(Unstreamable(1)));
Values(Unstreamable(1)));
// Verify that we can create a hierarchy of test fixtures, where the base // Verify that we can create a hierarchy of test fixtures, where the base
// class fixture is not parameterized and the derived class is. In this case // class fixture is not parameterized and the derived class is. In this case
...@@ -1029,7 +1021,8 @@ TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) { ...@@ -1029,7 +1021,8 @@ TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) {
".* value-parameterized test .*"); ".* value-parameterized test .*");
} }
INSTANTIATE_TEST_CASE_P(RangeZeroToFive, ParameterizedDerivedTest, Range(0, 5)); INSTANTIATE_TEST_SUITE_P(RangeZeroToFive, ParameterizedDerivedTest,
Range(0, 5));
// Tests param generator working with Enums // Tests param generator working with Enums
enum MyEnums { enum MyEnums {
...@@ -1041,19 +1034,19 @@ enum MyEnums { ...@@ -1041,19 +1034,19 @@ enum MyEnums {
class MyEnumTest : public testing::TestWithParam<MyEnums> {}; class MyEnumTest : public testing::TestWithParam<MyEnums> {};
TEST_P(MyEnumTest, ChecksParamMoreThanZero) { EXPECT_GE(10, GetParam()); } TEST_P(MyEnumTest, ChecksParamMoreThanZero) { EXPECT_GE(10, GetParam()); }
INSTANTIATE_TEST_CASE_P(MyEnumTests, MyEnumTest, INSTANTIATE_TEST_SUITE_P(MyEnumTests, MyEnumTest,
::testing::Values(ENUM1, ENUM2, 0)); ::testing::Values(ENUM1, ENUM2, 0));
int main(int argc, char **argv) { int main(int argc, char **argv) {
// Used in TestGenerationTest test case. // Used in TestGenerationTest test suite.
AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance()); AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance());
// Used in GeneratorEvaluationTest test case. Tests that the updated value // Used in GeneratorEvaluationTest test suite. Tests that the updated value
// will be picked up for instantiating tests in GeneratorEvaluationTest. // will be picked up for instantiating tests in GeneratorEvaluationTest.
GeneratorEvaluationTest::set_param_value(1); GeneratorEvaluationTest::set_param_value(1);
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
// Used in GeneratorEvaluationTest test case. Tests that value updated // Used in GeneratorEvaluationTest test suite. Tests that value updated
// here will NOT be used for instantiating tests in // here will NOT be used for instantiating tests in
// GeneratorEvaluationTest. // GeneratorEvaluationTest.
GeneratorEvaluationTest::set_param_value(2); GeneratorEvaluationTest::set_param_value(2);
......
...@@ -44,7 +44,7 @@ class ExternalInstantiationTest : public ::testing::TestWithParam<int> { ...@@ -44,7 +44,7 @@ class ExternalInstantiationTest : public ::testing::TestWithParam<int> {
// Test fixture for testing instantiation of a test in multiple // Test fixture for testing instantiation of a test in multiple
// translation units. // translation units.
class InstantiationInMultipleTranslaionUnitsTest class InstantiationInMultipleTranslationUnitsTest
: public ::testing::TestWithParam<int> { : public ::testing::TestWithParam<int> {
}; };
......
...@@ -46,16 +46,16 @@ ParamGenerator<int> extern_gen = Values(33); ...@@ -46,16 +46,16 @@ ParamGenerator<int> extern_gen = Values(33);
// and instantiated in another. The test is defined in // and instantiated in another. The test is defined in
// googletest-param-test-test.cc and ExternalInstantiationTest fixture class is // googletest-param-test-test.cc and ExternalInstantiationTest fixture class is
// defined in gtest-param-test_test.h. // defined in gtest-param-test_test.h.
INSTANTIATE_TEST_CASE_P(MultiplesOf33, INSTANTIATE_TEST_SUITE_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 // in googletest-param-test-test.cc and
// InstantiationInMultipleTranslaionUnitsTest fixture is defined in // InstantiationInMultipleTranslationUnitsTest fixture is defined in
// gtest-param-test_test.h // gtest-param-test_test.h
INSTANTIATE_TEST_CASE_P(Sequence2, INSTANTIATE_TEST_SUITE_P(Sequence2,
InstantiationInMultipleTranslaionUnitsTest, InstantiationInMultipleTranslationUnitsTest,
Values(42*3, 42*4, 42*5)); Values(42*3, 42*4, 42*5));
...@@ -286,7 +286,9 @@ TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFileAndLine) { ...@@ -286,7 +286,9 @@ TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFileAndLine) {
EXPECT_EQ("unknown file", FormatCompilerIndependentFileLocation(nullptr, -1)); EXPECT_EQ("unknown file", FormatCompilerIndependentFileLocation(nullptr, -1));
} }
#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_QNX || GTEST_OS_FUCHSIA #if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_QNX || GTEST_OS_FUCHSIA || \
GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \
GTEST_OS_NETBSD || GTEST_OS_OPENBSD
void* ThreadFunc(void* data) { void* ThreadFunc(void* data) {
internal::Mutex* mutex = static_cast<internal::Mutex*>(data); internal::Mutex* mutex = static_cast<internal::Mutex*>(data);
mutex->Lock(); mutex->Lock();
...@@ -386,14 +388,9 @@ class RETest : public ::testing::Test {}; ...@@ -386,14 +388,9 @@ class RETest : public ::testing::Test {};
// Defines StringTypes as the list of all string types that class RE // Defines StringTypes as the list of all string types that class RE
// supports. // supports.
typedef testing::Types< typedef testing::Types< ::std::string, const char*> StringTypes;
::std::string,
# if GTEST_HAS_GLOBAL_STRING
::string,
# endif // GTEST_HAS_GLOBAL_STRING
const char*> StringTypes;
TYPED_TEST_CASE(RETest, StringTypes); TYPED_TEST_SUITE(RETest, StringTypes);
// Tests RE's implicit constructors. // Tests RE's implicit constructors.
TYPED_TEST(RETest, ImplicitConstructorWorks) { TYPED_TEST(RETest, ImplicitConstructorWorks) {
...@@ -1051,7 +1048,7 @@ class AtomicCounterWithMutex { ...@@ -1051,7 +1048,7 @@ class AtomicCounterWithMutex {
pthread_mutex_init(&memory_barrier_mutex, nullptr)); pthread_mutex_init(&memory_barrier_mutex, nullptr));
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&memory_barrier_mutex)); GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&memory_barrier_mutex));
SleepMilliseconds(random_.Generate(30)); SleepMilliseconds(static_cast<int>(random_.Generate(30)));
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&memory_barrier_mutex)); GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&memory_barrier_mutex));
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&memory_barrier_mutex)); GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&memory_barrier_mutex));
...@@ -1059,7 +1056,7 @@ class AtomicCounterWithMutex { ...@@ -1059,7 +1056,7 @@ class AtomicCounterWithMutex {
// On Windows, performing an interlocked access puts up a memory barrier. // On Windows, performing an interlocked access puts up a memory barrier.
volatile LONG dummy = 0; volatile LONG dummy = 0;
::InterlockedIncrement(&dummy); ::InterlockedIncrement(&dummy);
SleepMilliseconds(random_.Generate(30)); SleepMilliseconds(static_cast<int>(random_.Generate(30)));
::InterlockedIncrement(&dummy); ::InterlockedIncrement(&dummy);
#else #else
# error "Memory barrier not implemented on this platform." # error "Memory barrier not implemented on this platform."
......
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