Unverified Commit edadfecd authored by Akash Patel's avatar Akash Patel Committed by GitHub
Browse files

Update gtest to 1.11.0 (#1086)

Properly resolves #1083, #996.
parent 26e3b704
......@@ -217,7 +217,6 @@ class Subprocess:
following attributes:
terminated_by_signal True if and only if the child process has been
terminated by a signal.
signal Sygnal that terminated the child process.
exited True if and only if the child process exited
normally.
exit_code The code with which the child process exited.
......@@ -289,10 +288,9 @@ class Subprocess:
else: # os.WIFEXITED(ret_code) should return True here.
self._return_code = os.WEXITSTATUS(ret_code)
if self._return_code < 0:
if bool(self._return_code & 0x80000000):
self.terminated_by_signal = True
self.exited = False
self.signal = -self._return_code
else:
self.terminated_by_signal = False
self.exited = True
......
......@@ -37,21 +37,22 @@
// code once "gtest.h" has been #included.
// Do not move it after other gtest #includes.
TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
bool dummy = testing::GTEST_FLAG(also_run_disabled_tests)
|| testing::GTEST_FLAG(break_on_failure)
|| testing::GTEST_FLAG(catch_exceptions)
|| testing::GTEST_FLAG(color) != "unknown"
|| testing::GTEST_FLAG(filter) != "unknown"
|| testing::GTEST_FLAG(list_tests)
|| testing::GTEST_FLAG(output) != "unknown"
|| testing::GTEST_FLAG(print_time)
|| testing::GTEST_FLAG(random_seed)
|| testing::GTEST_FLAG(repeat) > 0
|| testing::GTEST_FLAG(show_internal_stack_frames)
|| testing::GTEST_FLAG(shuffle)
|| testing::GTEST_FLAG(stack_trace_depth) > 0
|| testing::GTEST_FLAG(stream_result_to) != "unknown"
|| testing::GTEST_FLAG(throw_on_failure);
bool dummy = testing::GTEST_FLAG(also_run_disabled_tests) ||
testing::GTEST_FLAG(break_on_failure) ||
testing::GTEST_FLAG(catch_exceptions) ||
testing::GTEST_FLAG(color) != "unknown" ||
testing::GTEST_FLAG(fail_fast) ||
testing::GTEST_FLAG(filter) != "unknown" ||
testing::GTEST_FLAG(list_tests) ||
testing::GTEST_FLAG(output) != "unknown" ||
testing::GTEST_FLAG(brief) || testing::GTEST_FLAG(print_time) ||
testing::GTEST_FLAG(random_seed) ||
testing::GTEST_FLAG(repeat) > 0 ||
testing::GTEST_FLAG(show_internal_stack_frames) ||
testing::GTEST_FLAG(shuffle) ||
testing::GTEST_FLAG(stack_trace_depth) > 0 ||
testing::GTEST_FLAG(stream_result_to) != "unknown" ||
testing::GTEST_FLAG(throw_on_failure);
EXPECT_TRUE(dummy || !dummy); // Suppresses warning that dummy is unused.
}
......@@ -60,8 +61,10 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
#include <string.h>
#include <time.h>
#include <cstdint>
#include <map>
#include <ostream>
#include <string>
#include <type_traits>
#include <unordered_set>
#include <vector>
......@@ -201,9 +204,11 @@ using testing::GTEST_FLAG(break_on_failure);
using testing::GTEST_FLAG(catch_exceptions);
using testing::GTEST_FLAG(color);
using testing::GTEST_FLAG(death_test_use_fork);
using testing::GTEST_FLAG(fail_fast);
using testing::GTEST_FLAG(filter);
using testing::GTEST_FLAG(list_tests);
using testing::GTEST_FLAG(output);
using testing::GTEST_FLAG(brief);
using testing::GTEST_FLAG(print_time);
using testing::GTEST_FLAG(random_seed);
using testing::GTEST_FLAG(repeat);
......@@ -214,17 +219,18 @@ using testing::GTEST_FLAG(stream_result_to);
using testing::GTEST_FLAG(throw_on_failure);
using testing::IsNotSubstring;
using testing::IsSubstring;
using testing::kMaxStackTraceDepth;
using testing::Message;
using testing::ScopedFakeTestPartResultReporter;
using testing::StaticAssertTypeEq;
using testing::Test;
using testing::TestCase;
using testing::TestEventListeners;
using testing::TestInfo;
using testing::TestPartResult;
using testing::TestPartResultArray;
using testing::TestProperty;
using testing::TestResult;
using testing::TestSuite;
using testing::TimeInMillis;
using testing::UnitTest;
using testing::internal::AlwaysFalse;
......@@ -240,7 +246,6 @@ using testing::internal::FloatingPoint;
using testing::internal::ForEach;
using testing::internal::FormatEpochTimeInMillisAsIso8601;
using testing::internal::FormatTimeInMillisAsSeconds;
using testing::internal::GTestFlagSaver;
using testing::internal::GetCurrentOsStackTraceExceptTop;
using testing::internal::GetElementOr;
using testing::internal::GetNextRandomSeed;
......@@ -249,12 +254,14 @@ using testing::internal::GetTestTypeId;
using testing::internal::GetTimeInMillis;
using testing::internal::GetTypeId;
using testing::internal::GetUnitTestImpl;
using testing::internal::Int32;
using testing::internal::GTestFlagSaver;
using testing::internal::HasDebugStringAndShortDebugString;
using testing::internal::Int32FromEnvOrDie;
using testing::internal::IsAProtocolMessage;
using testing::internal::IsContainer;
using testing::internal::IsContainerTest;
using testing::internal::IsNotContainer;
using testing::internal::kMaxRandomSeed;
using testing::internal::kTestTypeIdInGoogleTest;
using testing::internal::NativeArray;
using testing::internal::OsStackTraceGetter;
using testing::internal::OsStackTraceGetterInterface;
......@@ -271,15 +278,11 @@ using testing::internal::StreamableToString;
using testing::internal::String;
using testing::internal::TestEventListenersAccessor;
using testing::internal::TestResultAccessor;
using testing::internal::UInt32;
using testing::internal::UnitTestImpl;
using testing::internal::WideStringToUtf8;
using testing::internal::edit_distance::CalculateOptimalEdits;
using testing::internal::edit_distance::CreateUnifiedDiff;
using testing::internal::edit_distance::EditType;
using testing::internal::kMaxRandomSeed;
using testing::internal::kTestTypeIdInGoogleTest;
using testing::kMaxStackTraceDepth;
#if GTEST_HAS_STREAM_REDIRECTION
using testing::internal::CaptureStdout;
......@@ -483,28 +486,28 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec;
TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsTwoDigitSegments) {
EXPECT_EQ("2011-10-31T18:52:42",
EXPECT_EQ("2011-10-31T18:52:42.000",
FormatEpochTimeInMillisAsIso8601(1320087162 * kMillisPerSec));
}
TEST_F(FormatEpochTimeInMillisAsIso8601Test, MillisecondsDoNotAffectResult) {
TEST_F(FormatEpochTimeInMillisAsIso8601Test, IncludesMillisecondsAfterDot) {
EXPECT_EQ(
"2011-10-31T18:52:42",
"2011-10-31T18:52:42.234",
FormatEpochTimeInMillisAsIso8601(1320087162 * kMillisPerSec + 234));
}
TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsLeadingZeroes) {
EXPECT_EQ("2011-09-03T05:07:02",
EXPECT_EQ("2011-09-03T05:07:02.000",
FormatEpochTimeInMillisAsIso8601(1315026422 * kMillisPerSec));
}
TEST_F(FormatEpochTimeInMillisAsIso8601Test, Prints24HourTime) {
EXPECT_EQ("2011-09-28T17:08:22",
EXPECT_EQ("2011-09-28T17:08:22.000",
FormatEpochTimeInMillisAsIso8601(1317229702 * kMillisPerSec));
}
TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
EXPECT_EQ("1970-01-01T00:00:00", FormatEpochTimeInMillisAsIso8601(0));
EXPECT_EQ("1970-01-01T00:00:00.000", FormatEpochTimeInMillisAsIso8601(0));
}
# ifdef __BORLANDC__
......@@ -788,7 +791,7 @@ TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) {
}
TEST(RandomTest, GeneratesNumbersWithinRange) {
const UInt32 kRange = 10000;
constexpr uint32_t kRange = 10000;
testing::internal::Random random(12345);
for (int i = 0; i < 10; i++) {
EXPECT_LT(random.Generate(kRange), kRange) << " for iteration " << i;
......@@ -801,10 +804,10 @@ TEST(RandomTest, GeneratesNumbersWithinRange) {
}
TEST(RandomTest, RepeatsWhenReseeded) {
const int kSeed = 123;
const int kArraySize = 10;
const UInt32 kRange = 10000;
UInt32 values[kArraySize];
constexpr int kSeed = 123;
constexpr int kArraySize = 10;
constexpr uint32_t kRange = 10000;
uint32_t values[kArraySize];
testing::internal::Random random(kSeed);
for (int i = 0; i < kArraySize; i++) {
......@@ -1599,9 +1602,11 @@ class GTestFlagSaverTest : public Test {
GTEST_FLAG(catch_exceptions) = false;
GTEST_FLAG(death_test_use_fork) = false;
GTEST_FLAG(color) = "auto";
GTEST_FLAG(fail_fast) = false;
GTEST_FLAG(filter) = "";
GTEST_FLAG(list_tests) = false;
GTEST_FLAG(output) = "";
GTEST_FLAG(brief) = false;
GTEST_FLAG(print_time) = true;
GTEST_FLAG(random_seed) = 0;
GTEST_FLAG(repeat) = 1;
......@@ -1626,9 +1631,11 @@ class GTestFlagSaverTest : public Test {
EXPECT_FALSE(GTEST_FLAG(catch_exceptions));
EXPECT_STREQ("auto", GTEST_FLAG(color).c_str());
EXPECT_FALSE(GTEST_FLAG(death_test_use_fork));
EXPECT_FALSE(GTEST_FLAG(fail_fast));
EXPECT_STREQ("", GTEST_FLAG(filter).c_str());
EXPECT_FALSE(GTEST_FLAG(list_tests));
EXPECT_STREQ("", GTEST_FLAG(output).c_str());
EXPECT_FALSE(GTEST_FLAG(brief));
EXPECT_TRUE(GTEST_FLAG(print_time));
EXPECT_EQ(0, GTEST_FLAG(random_seed));
EXPECT_EQ(1, GTEST_FLAG(repeat));
......@@ -1642,9 +1649,11 @@ class GTestFlagSaverTest : public Test {
GTEST_FLAG(catch_exceptions) = true;
GTEST_FLAG(color) = "no";
GTEST_FLAG(death_test_use_fork) = true;
GTEST_FLAG(fail_fast) = true;
GTEST_FLAG(filter) = "abc";
GTEST_FLAG(list_tests) = true;
GTEST_FLAG(output) = "xml:foo.xml";
GTEST_FLAG(brief) = true;
GTEST_FLAG(print_time) = false;
GTEST_FLAG(random_seed) = 1;
GTEST_FLAG(repeat) = 100;
......@@ -1772,7 +1781,7 @@ TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
// Tests that ParseInt32Flag() returns false and doesn't change the
// output value when the flag has wrong format
TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
Int32 value = 123;
int32_t value = 123;
EXPECT_FALSE(ParseInt32Flag("--a=100", "b", &value));
EXPECT_EQ(123, value);
......@@ -1785,7 +1794,7 @@ TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
printf("(expecting 2 warnings)\n");
Int32 value = 123;
int32_t value = 123;
EXPECT_FALSE(ParseInt32Flag("--abc=12345678987654321", "abc", &value));
EXPECT_EQ(123, value);
......@@ -1799,7 +1808,7 @@ TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
printf("(expecting 2 warnings)\n");
Int32 value = 123;
int32_t value = 123;
EXPECT_FALSE(ParseInt32Flag("--abc=A1", "abc", &value));
EXPECT_EQ(123, value);
......@@ -1811,7 +1820,7 @@ TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
// returns true when the flag represents a valid decimal integer in
// the range of an Int32.
TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
Int32 value = 123;
int32_t value = 123;
EXPECT_TRUE(ParseInt32Flag("--" GTEST_FLAG_PREFIX_ "abc=456", "abc", &value));
EXPECT_EQ(456, value);
......@@ -1834,7 +1843,7 @@ TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
#endif // !GTEST_OS_WINDOWS_MOBILE
// Tests that Int32FromEnvOrDie() aborts with an error message
// if the variable is not an Int32.
// if the variable is not an int32_t.
TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "xxx");
EXPECT_DEATH_IF_SUPPORTED(
......@@ -1843,7 +1852,7 @@ TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
}
// Tests that Int32FromEnvOrDie() aborts with an error message
// if the variable cannot be represented by an Int32.
// if the variable cannot be represented by an int32_t.
TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "1234567891234567891234");
EXPECT_DEATH_IF_SUPPORTED(
......@@ -2759,7 +2768,7 @@ class FloatingPointTest : public Test {
typedef typename Floating::Bits Bits;
void SetUp() override {
const size_t max_ulps = Floating::kMaxUlps;
const uint32_t max_ulps = Floating::kMaxUlps;
// The bits that represent 0.0.
const Bits zero_bits = Floating(0).bits();
......@@ -2924,22 +2933,18 @@ TEST_F(FloatTest, Commutative) {
TEST_F(FloatTest, EXPECT_NEAR) {
EXPECT_NEAR(-1.0f, -1.1f, 0.2f);
EXPECT_NEAR(2.0f, 3.0f, 1.0f);
EXPECT_NONFATAL_FAILURE(EXPECT_NEAR(1.0f,1.5f, 0.25f), // NOLINT
EXPECT_NONFATAL_FAILURE(EXPECT_NEAR(1.0f, 1.5f, 0.25f), // NOLINT
"The difference between 1.0f and 1.5f is 0.5, "
"which exceeds 0.25f");
// To work around a bug in gcc 2.95.0, there is intentionally no
// space after the first comma in the previous line.
}
// Tests ASSERT_NEAR.
TEST_F(FloatTest, ASSERT_NEAR) {
ASSERT_NEAR(-1.0f, -1.1f, 0.2f);
ASSERT_NEAR(2.0f, 3.0f, 1.0f);
EXPECT_FATAL_FAILURE(ASSERT_NEAR(1.0f,1.5f, 0.25f), // NOLINT
EXPECT_FATAL_FAILURE(ASSERT_NEAR(1.0f, 1.5f, 0.25f), // NOLINT
"The difference between 1.0f and 1.5f is 0.5, "
"which exceeds 0.25f");
// To work around a bug in gcc 2.95.0, there is intentionally no
// space after the first comma in the previous line.
}
// Tests the cases where FloatLE() should succeed.
......@@ -3080,8 +3085,13 @@ TEST_F(DoubleTest, EXPECT_NEAR) {
EXPECT_NONFATAL_FAILURE(EXPECT_NEAR(1.0, 1.5, 0.25), // NOLINT
"The difference between 1.0 and 1.5 is 0.5, "
"which exceeds 0.25");
// To work around a bug in gcc 2.95.0, there is intentionally no
// space after the first comma in the previous statement.
// At this magnitude adjacent doubles are 512.0 apart, so this triggers a
// slightly different failure reporting path.
EXPECT_NONFATAL_FAILURE(
EXPECT_NEAR(4.2934311416234112e+18, 4.2934311416234107e+18, 1.0),
"The abs_error parameter 1.0 evaluates to 1 which is smaller than the "
"minimum distance between doubles for numbers of this magnitude which is "
"512");
}
// Tests ASSERT_NEAR.
......@@ -3091,8 +3101,6 @@ TEST_F(DoubleTest, ASSERT_NEAR) {
EXPECT_FATAL_FAILURE(ASSERT_NEAR(1.0, 1.5, 0.25), // NOLINT
"The difference between 1.0 and 1.5 is 0.5, "
"which exceeds 0.25");
// To work around a bug in gcc 2.95.0, there is intentionally no
// space after the first comma in the previous statement.
}
// Tests the cases where DoubleLE() should succeed.
......@@ -3179,8 +3187,6 @@ TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) {
// Tests that disabled typed tests aren't run.
#if GTEST_HAS_TYPED_TEST
template <typename T>
class TypedTest : public Test {
};
......@@ -3202,12 +3208,8 @@ TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) {
FAIL() << "Unexpected failure: Disabled typed test should not run.";
}
#endif // GTEST_HAS_TYPED_TEST
// Tests that disabled type-parameterized tests aren't run.
#if GTEST_HAS_TYPED_TEST_P
template <typename T>
class TypedTestP : public Test {
};
......@@ -3238,8 +3240,6 @@ REGISTER_TYPED_TEST_SUITE_P(DISABLED_TypedTestP, ShouldNotRun);
INSTANTIATE_TYPED_TEST_SUITE_P(My, DISABLED_TypedTestP, NumericTypes);
#endif // GTEST_HAS_TYPED_TEST_P
// Tests that assertion macros evaluate their arguments exactly once.
class SingleEvaluationTest : public Test {
......@@ -3345,9 +3345,26 @@ TEST_F(SingleEvaluationTest, OtherCases) {
#if GTEST_HAS_EXCEPTIONS
#if GTEST_HAS_RTTI
#ifdef _MSC_VER
#define ERROR_DESC "class std::runtime_error"
#else
#define ERROR_DESC "std::runtime_error"
#endif
#else // GTEST_HAS_RTTI
#define ERROR_DESC "an std::exception-derived error"
#endif // GTEST_HAS_RTTI
void ThrowAnInteger() {
throw 1;
}
void ThrowRuntimeError(const char* what) {
throw std::runtime_error(what);
}
// Tests that assertion arguments are evaluated exactly once.
TEST_F(SingleEvaluationTest, ExceptionTests) {
......@@ -3365,31 +3382,38 @@ TEST_F(SingleEvaluationTest, ExceptionTests) {
}, bool), "throws a different type");
EXPECT_EQ(2, a_);
// failed EXPECT_THROW, throws runtime error
EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT
a_++;
ThrowRuntimeError("A description");
}, bool), "throws " ERROR_DESC " with description \"A description\"");
EXPECT_EQ(3, a_);
// failed EXPECT_THROW, throws nothing
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(a_++, bool), "throws nothing");
EXPECT_EQ(3, a_);
EXPECT_EQ(4, a_);
// successful EXPECT_NO_THROW
EXPECT_NO_THROW(a_++);
EXPECT_EQ(4, a_);
EXPECT_EQ(5, a_);
// failed EXPECT_NO_THROW
EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW({ // NOLINT
a_++;
ThrowAnInteger();
}), "it throws");
EXPECT_EQ(5, a_);
EXPECT_EQ(6, a_);
// successful EXPECT_ANY_THROW
EXPECT_ANY_THROW({ // NOLINT
a_++;
ThrowAnInteger();
});
EXPECT_EQ(6, a_);
EXPECT_EQ(7, a_);
// failed EXPECT_ANY_THROW
EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(a_++), "it doesn't");
EXPECT_EQ(7, a_);
EXPECT_EQ(8, a_);
}
#endif // GTEST_HAS_EXCEPTIONS
......@@ -3734,10 +3758,6 @@ TEST(AssertionTest, ASSERT_EQ) {
TEST(AssertionTest, ASSERT_EQ_NULL) {
// A success.
const char* p = nullptr;
// Some older GCC versions may issue a spurious warning in this or the next
// assertion statement. This warning should not be suppressed with
// static_cast since the test verifies the ability to use bare NULL as the
// expected parameter to the macro.
ASSERT_EQ(nullptr, p);
// A failure.
......@@ -3813,6 +3833,12 @@ TEST(AssertionTest, ASSERT_THROW) {
ASSERT_THROW(ThrowAnInteger(), bool),
"Expected: ThrowAnInteger() throws an exception of type bool.\n"
" Actual: it throws a different type.");
EXPECT_FATAL_FAILURE(
ASSERT_THROW(ThrowRuntimeError("A description"), std::logic_error),
"Expected: ThrowRuntimeError(\"A description\") "
"throws an exception of type std::logic_error.\n "
"Actual: it throws " ERROR_DESC " "
"with description \"A description\".");
# endif
EXPECT_FATAL_FAILURE(
......@@ -3827,6 +3853,11 @@ TEST(AssertionTest, ASSERT_NO_THROW) {
EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()),
"Expected: ThrowAnInteger() doesn't throw an exception."
"\n Actual: it throws.");
EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowRuntimeError("A description")),
"Expected: ThrowRuntimeError(\"A description\") "
"doesn't throw an exception.\n "
"Actual: it throws " ERROR_DESC " "
"with description \"A description\".");
}
// Tests ASSERT_ANY_THROW.
......@@ -4096,11 +4127,13 @@ TEST(HRESULTAssertionTest, Streaming) {
#endif // GTEST_OS_WINDOWS
#ifdef __BORLANDC__
// Silences warnings: "Condition is always true", "Unreachable code"
# pragma option push -w-ccc -w-rch
// The following code intentionally tests a suboptimal syntax.
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-else"
#pragma GCC diagnostic ignored "-Wempty-body"
#pragma GCC diagnostic ignored "-Wpragmas"
#endif
// Tests that the assertion macros behave like single statements.
TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
if (AlwaysFalse())
......@@ -4120,6 +4153,9 @@ TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
else
EXPECT_GT(3, 2) << "";
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#if GTEST_HAS_EXCEPTIONS
// Tests that the compiler will not complain about unreachable code in the
......@@ -4136,6 +4172,17 @@ TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(n++), "");
}
TEST(ExpectThrowTest, DoesNotGenerateDuplicateCatchClauseWarning) {
EXPECT_THROW(throw std::exception(), std::exception);
}
// The following code intentionally tests a suboptimal syntax.
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-else"
#pragma GCC diagnostic ignored "-Wempty-body"
#pragma GCC diagnostic ignored "-Wpragmas"
#endif
TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
if (AlwaysFalse())
EXPECT_THROW(ThrowNothing(), bool);
......@@ -4161,8 +4208,19 @@ TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
else
; // NOLINT
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif // GTEST_HAS_EXCEPTIONS
// The following code intentionally tests a suboptimal syntax.
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-else"
#pragma GCC diagnostic ignored "-Wempty-body"
#pragma GCC diagnostic ignored "-Wpragmas"
#endif
TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
if (AlwaysFalse())
EXPECT_NO_FATAL_FAILURE(FAIL()) << "This should never be executed. "
......@@ -4185,6 +4243,9 @@ TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
else
ASSERT_NO_FATAL_FAILURE(SUCCEED());
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
// Tests that the assertion macros work well with switch statements.
TEST(AssertionSyntaxTest, WorksWithSwitch) {
......@@ -4314,10 +4375,8 @@ TEST(AssertionWithMessageTest, ASSERT_STR) {
TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
ASSERT_FLOAT_EQ(1, 1) << "This should succeed.";
ASSERT_DOUBLE_EQ(1, 1) << "This should succeed.";
EXPECT_FATAL_FAILURE(ASSERT_NEAR(1,1.2, 0.1) << "Expect failure.", // NOLINT
EXPECT_FATAL_FAILURE(ASSERT_NEAR(1, 1.2, 0.1) << "Expect failure.", // NOLINT
"Expect failure.");
// To work around a bug in gcc 2.95.0, there is intentionally no
// space after the first comma in the previous statement.
}
// Tests using ASSERT_FALSE with a streamed message.
......@@ -4458,10 +4517,6 @@ TEST(ExpectTest, EXPECT_EQ_Double) {
TEST(ExpectTest, EXPECT_EQ_NULL) {
// A success.
const char* p = nullptr;
// Some older GCC versions may issue a spurious warning in this or the next
// assertion statement. This warning should not be suppressed with
// static_cast since the test verifies the ability to use bare NULL as the
// expected parameter to the macro.
EXPECT_EQ(nullptr, p);
// A failure.
......@@ -4552,6 +4607,12 @@ TEST(ExpectTest, EXPECT_THROW) {
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool),
"Expected: ThrowAnInteger() throws an exception of "
"type bool.\n Actual: it throws a different type.");
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowRuntimeError("A description"),
std::logic_error),
"Expected: ThrowRuntimeError(\"A description\") "
"throws an exception of type std::logic_error.\n "
"Actual: it throws " ERROR_DESC " "
"with description \"A description\".");
EXPECT_NONFATAL_FAILURE(
EXPECT_THROW(ThrowNothing(), bool),
"Expected: ThrowNothing() throws an exception of type bool.\n"
......@@ -4564,6 +4625,11 @@ TEST(ExpectTest, EXPECT_NO_THROW) {
EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()),
"Expected: ThrowAnInteger() doesn't throw an "
"exception.\n Actual: it throws.");
EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowRuntimeError("A description")),
"Expected: ThrowRuntimeError(\"A description\") "
"doesn't throw an exception.\n "
"Actual: it throws " ERROR_DESC " "
"with description \"A description\".");
}
// Tests EXPECT_ANY_THROW.
......@@ -5303,7 +5369,7 @@ class TestInfoTest : public Test {
TEST_F(TestInfoTest, Names) {
const TestInfo* const test_info = GetTestInfo("Names");
ASSERT_STREQ("TestInfoTest", test_info->test_case_name());
ASSERT_STREQ("TestInfoTest", test_info->test_suite_name());
ASSERT_STREQ("Names", test_info->name());
}
......@@ -5373,7 +5439,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, CodeLocationForTYPEDTESTP, int);
// Tests setting up and tearing down a test case.
// Legacy API is deprecated but still available
#ifndef REMOVE_LEGACY_TEST_CASEAPI
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
class SetUpTestCaseTest : public Test {
protected:
// This will be called once before the first test in this test case
......@@ -5432,7 +5498,7 @@ TEST_F(SetUpTestCaseTest, Test1) { EXPECT_STRNE(nullptr, shared_resource_); }
TEST_F(SetUpTestCaseTest, Test2) {
EXPECT_STREQ("123", shared_resource_);
}
#endif // REMOVE_LEGACY_TEST_CASEAPI
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// Tests SetupTestSuite/TearDown TestSuite
class SetUpTestSuiteTest : public Test {
......@@ -5501,20 +5567,23 @@ TEST_F(SetUpTestSuiteTest, TestSetupTestSuite2) {
// The Flags struct stores a copy of all Google Test flags.
struct Flags {
// Constructs a Flags struct where each flag has its default value.
Flags() : also_run_disabled_tests(false),
break_on_failure(false),
catch_exceptions(false),
death_test_use_fork(false),
filter(""),
list_tests(false),
output(""),
print_time(true),
random_seed(0),
repeat(1),
shuffle(false),
stack_trace_depth(kMaxStackTraceDepth),
stream_result_to(""),
throw_on_failure(false) {}
Flags()
: also_run_disabled_tests(false),
break_on_failure(false),
catch_exceptions(false),
death_test_use_fork(false),
fail_fast(false),
filter(""),
list_tests(false),
output(""),
brief(false),
print_time(true),
random_seed(0),
repeat(1),
shuffle(false),
stack_trace_depth(kMaxStackTraceDepth),
stream_result_to(""),
throw_on_failure(false) {}
// Factory methods.
......@@ -5550,6 +5619,14 @@ struct Flags {
return flags;
}
// Creates a Flags struct where the gtest_fail_fast flag has
// the given value.
static Flags FailFast(bool fail_fast) {
Flags flags;
flags.fail_fast = fail_fast;
return flags;
}
// Creates a Flags struct where the gtest_filter flag has the given
// value.
static Flags Filter(const char* filter) {
......@@ -5574,6 +5651,14 @@ struct Flags {
return flags;
}
// Creates a Flags struct where the gtest_brief flag has the given
// value.
static Flags Brief(bool brief) {
Flags flags;
flags.brief = brief;
return flags;
}
// Creates a Flags struct where the gtest_print_time flag has the given
// value.
static Flags PrintTime(bool print_time) {
......@@ -5584,7 +5669,7 @@ struct Flags {
// Creates a Flags struct where the gtest_random_seed flag has the given
// value.
static Flags RandomSeed(Int32 random_seed) {
static Flags RandomSeed(int32_t random_seed) {
Flags flags;
flags.random_seed = random_seed;
return flags;
......@@ -5592,7 +5677,7 @@ struct Flags {
// Creates a Flags struct where the gtest_repeat flag has the given
// value.
static Flags Repeat(Int32 repeat) {
static Flags Repeat(int32_t repeat) {
Flags flags;
flags.repeat = repeat;
return flags;
......@@ -5608,7 +5693,7 @@ struct Flags {
// Creates a Flags struct where the GTEST_FLAG(stack_trace_depth) flag has
// the given value.
static Flags StackTraceDepth(Int32 stack_trace_depth) {
static Flags StackTraceDepth(int32_t stack_trace_depth) {
Flags flags;
flags.stack_trace_depth = stack_trace_depth;
return flags;
......@@ -5635,14 +5720,16 @@ struct Flags {
bool break_on_failure;
bool catch_exceptions;
bool death_test_use_fork;
bool fail_fast;
const char* filter;
bool list_tests;
const char* output;
bool brief;
bool print_time;
Int32 random_seed;
Int32 repeat;
int32_t random_seed;
int32_t repeat;
bool shuffle;
Int32 stack_trace_depth;
int32_t stack_trace_depth;
const char* stream_result_to;
bool throw_on_failure;
};
......@@ -5656,9 +5743,11 @@ class ParseFlagsTest : public Test {
GTEST_FLAG(break_on_failure) = false;
GTEST_FLAG(catch_exceptions) = false;
GTEST_FLAG(death_test_use_fork) = false;
GTEST_FLAG(fail_fast) = false;
GTEST_FLAG(filter) = "";
GTEST_FLAG(list_tests) = false;
GTEST_FLAG(output) = "";
GTEST_FLAG(brief) = false;
GTEST_FLAG(print_time) = true;
GTEST_FLAG(random_seed) = 0;
GTEST_FLAG(repeat) = 1;
......@@ -5686,9 +5775,11 @@ class ParseFlagsTest : public Test {
EXPECT_EQ(expected.break_on_failure, GTEST_FLAG(break_on_failure));
EXPECT_EQ(expected.catch_exceptions, GTEST_FLAG(catch_exceptions));
EXPECT_EQ(expected.death_test_use_fork, GTEST_FLAG(death_test_use_fork));
EXPECT_EQ(expected.fail_fast, GTEST_FLAG(fail_fast));
EXPECT_STREQ(expected.filter, GTEST_FLAG(filter).c_str());
EXPECT_EQ(expected.list_tests, GTEST_FLAG(list_tests));
EXPECT_STREQ(expected.output, GTEST_FLAG(output).c_str());
EXPECT_EQ(expected.brief, GTEST_FLAG(brief));
EXPECT_EQ(expected.print_time, GTEST_FLAG(print_time));
EXPECT_EQ(expected.random_seed, GTEST_FLAG(random_seed));
EXPECT_EQ(expected.repeat, GTEST_FLAG(repeat));
......@@ -5772,6 +5863,15 @@ TEST_F(ParseFlagsTest, NoFlag) {
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), false);
}
// Tests parsing --gtest_fail_fast.
TEST_F(ParseFlagsTest, FailFast) {
const char* argv[] = {"foo.exe", "--gtest_fail_fast", nullptr};
const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::FailFast(true), false);
}
// Tests parsing a bad --gtest_filter flag.
TEST_F(ParseFlagsTest, FilterBad) {
const char* argv[] = {"foo.exe", "--gtest_filter", nullptr};
......@@ -5971,6 +6071,33 @@ TEST_F(ParseFlagsTest, OutputXmlDirectory) {
Flags::Output("xml:directory/path/"), false);
}
// Tests having a --gtest_brief flag
TEST_F(ParseFlagsTest, BriefFlag) {
const char* argv[] = {"foo.exe", "--gtest_brief", nullptr};
const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Brief(true), false);
}
// Tests having a --gtest_brief flag with a "true" value
TEST_F(ParseFlagsTest, BriefFlagTrue) {
const char* argv[] = {"foo.exe", "--gtest_brief=1", nullptr};
const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Brief(true), false);
}
// Tests having a --gtest_brief flag with a "false" value
TEST_F(ParseFlagsTest, BriefFlagFalse) {
const char* argv[] = {"foo.exe", "--gtest_brief=0", nullptr};
const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Brief(false), false);
}
// Tests having a --gtest_print_time flag
TEST_F(ParseFlagsTest, PrintTimeFlag) {
const char* argv[] = {"foo.exe", "--gtest_print_time", nullptr};
......@@ -6170,7 +6297,7 @@ TEST_F(ParseFlagsTest, WideStrings) {
#if GTEST_USE_OWN_FLAGFILE_FLAG_
class FlagfileTest : public ParseFlagsTest {
public:
virtual void SetUp() {
void SetUp() override {
ParseFlagsTest::SetUp();
testdata_path_.Set(internal::FilePath(
......@@ -6180,7 +6307,7 @@ class FlagfileTest : public ParseFlagsTest {
EXPECT_TRUE(testdata_path_.CreateFolder());
}
virtual void TearDown() {
void TearDown() override {
testing::internal::posix::RmDir(testdata_path_.c_str());
ParseFlagsTest::TearDown();
}
......@@ -6277,8 +6404,8 @@ TEST_F(CurrentTestInfoTest, WorksForFirstTestInATestSuite) {
UnitTest::GetInstance()->current_test_info();
ASSERT_TRUE(nullptr != test_info)
<< "There is a test running so we should have a valid TestInfo.";
EXPECT_STREQ("CurrentTestInfoTest", test_info->test_case_name())
<< "Expected the name of the currently running test case.";
EXPECT_STREQ("CurrentTestInfoTest", test_info->test_suite_name())
<< "Expected the name of the currently running test suite.";
EXPECT_STREQ("WorksForFirstTestInATestSuite", test_info->name())
<< "Expected the name of the currently running test.";
}
......@@ -6292,8 +6419,8 @@ TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestSuite) {
UnitTest::GetInstance()->current_test_info();
ASSERT_TRUE(nullptr != test_info)
<< "There is a test running so we should have a valid TestInfo.";
EXPECT_STREQ("CurrentTestInfoTest", test_info->test_case_name())
<< "Expected the name of the currently running test case.";
EXPECT_STREQ("CurrentTestInfoTest", test_info->test_suite_name())
<< "Expected the name of the currently running test suite.";
EXPECT_STREQ("WorksForSecondTestInATestSuite", test_info->name())
<< "Expected the name of the currently running test.";
}
......@@ -7081,24 +7208,71 @@ GTEST_TEST(AlternativeNameTest, Works) { // GTEST_TEST is the same as TEST.
class ConversionHelperBase {};
class ConversionHelperDerived : public ConversionHelperBase {};
// Tests that IsAProtocolMessage<T>::value is a compile-time constant.
TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
GTEST_COMPILE_ASSERT_(IsAProtocolMessage<::proto2::Message>::value,
const_true);
GTEST_COMPILE_ASSERT_(!IsAProtocolMessage<int>::value, const_false);
}
struct HasDebugStringMethods {
std::string DebugString() const { return ""; }
std::string ShortDebugString() const { return ""; }
};
// Tests that IsAProtocolMessage<T>::value is true when T is
// proto2::Message or a sub-class of it.
TEST(IsAProtocolMessageTest, ValueIsTrueWhenTypeIsAProtocolMessage) {
EXPECT_TRUE(IsAProtocolMessage< ::proto2::Message>::value);
struct InheritsDebugStringMethods : public HasDebugStringMethods {};
struct WrongTypeDebugStringMethod {
std::string DebugString() const { return ""; }
int ShortDebugString() const { return 1; }
};
struct NotConstDebugStringMethod {
std::string DebugString() { return ""; }
std::string ShortDebugString() const { return ""; }
};
struct MissingDebugStringMethod {
std::string DebugString() { return ""; }
};
struct IncompleteType;
// Tests that HasDebugStringAndShortDebugString<T>::value is a compile-time
// constant.
TEST(HasDebugStringAndShortDebugStringTest, ValueIsCompileTimeConstant) {
GTEST_COMPILE_ASSERT_(
HasDebugStringAndShortDebugString<HasDebugStringMethods>::value,
const_true);
GTEST_COMPILE_ASSERT_(
HasDebugStringAndShortDebugString<InheritsDebugStringMethods>::value,
const_true);
GTEST_COMPILE_ASSERT_(HasDebugStringAndShortDebugString<
const InheritsDebugStringMethods>::value,
const_true);
GTEST_COMPILE_ASSERT_(
!HasDebugStringAndShortDebugString<WrongTypeDebugStringMethod>::value,
const_false);
GTEST_COMPILE_ASSERT_(
!HasDebugStringAndShortDebugString<NotConstDebugStringMethod>::value,
const_false);
GTEST_COMPILE_ASSERT_(
!HasDebugStringAndShortDebugString<MissingDebugStringMethod>::value,
const_false);
GTEST_COMPILE_ASSERT_(
!HasDebugStringAndShortDebugString<IncompleteType>::value, const_false);
GTEST_COMPILE_ASSERT_(!HasDebugStringAndShortDebugString<int>::value,
const_false);
}
// Tests that HasDebugStringAndShortDebugString<T>::value is true when T has
// needed methods.
TEST(HasDebugStringAndShortDebugStringTest,
ValueIsTrueWhenTypeHasDebugStringAndShortDebugString) {
EXPECT_TRUE(
HasDebugStringAndShortDebugString<InheritsDebugStringMethods>::value);
}
// Tests that IsAProtocolMessage<T>::value is false when T is neither
// ::proto2::Message nor a sub-class of it.
TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) {
EXPECT_FALSE(IsAProtocolMessage<int>::value);
EXPECT_FALSE(IsAProtocolMessage<const ConversionHelperBase>::value);
// Tests that HasDebugStringAndShortDebugString<T>::value is false when T
// doesn't have needed methods.
TEST(HasDebugStringAndShortDebugStringTest,
ValueIsFalseWhenTypeIsNotAProtocolMessage) {
EXPECT_FALSE(HasDebugStringAndShortDebugString<int>::value);
EXPECT_FALSE(
HasDebugStringAndShortDebugString<const ConversionHelperBase>::value);
}
// Tests GTEST_REMOVE_REFERENCE_AND_CONST_.
......@@ -7353,20 +7527,15 @@ TEST(IndexSequence, MakeIndexSequence) {
// ElemFromList
TEST(ElemFromList, Basic) {
using testing::internal::ElemFromList;
using Idx = testing::internal::MakeIndexSequence<3>::type;
EXPECT_TRUE((
std::is_same<int, ElemFromList<0, Idx, int, double, char>::type>::value));
EXPECT_TRUE(
(std::is_same<double,
ElemFromList<1, Idx, int, double, char>::type>::value));
(std::is_same<int, ElemFromList<0, int, double, char>::type>::value));
EXPECT_TRUE(
(std::is_same<char,
ElemFromList<2, Idx, int, double, char>::type>::value));
(std::is_same<double, ElemFromList<1, int, double, char>::type>::value));
EXPECT_TRUE(
(std::is_same<
char, ElemFromList<7, testing::internal::MakeIndexSequence<12>::type,
int, int, int, int, int, int, int, char, int, int,
int, int>::type>::value));
(std::is_same<char, ElemFromList<2, int, double, char>::type>::value));
EXPECT_TRUE((
std::is_same<char, ElemFromList<7, int, int, int, int, int, int, int,
char, int, int, int, int>::type>::value));
}
// FlatTuple
......@@ -7378,7 +7547,8 @@ TEST(FlatTuple, Basic) {
EXPECT_EQ(0.0, tuple.Get<1>());
EXPECT_EQ(nullptr, tuple.Get<2>());
tuple = FlatTuple<int, double, const char*>(7, 3.2, "Foo");
tuple = FlatTuple<int, double, const char*>(
testing::internal::FlatTupleConstructTag{}, 7, 3.2, "Foo");
EXPECT_EQ(7, tuple.Get<0>());
EXPECT_EQ(3.2, tuple.Get<1>());
EXPECT_EQ(std::string("Foo"), tuple.Get<2>());
......@@ -7387,6 +7557,147 @@ TEST(FlatTuple, Basic) {
EXPECT_EQ(5.1, tuple.Get<1>());
}
namespace {
std::string AddIntToString(int i, const std::string& s) {
return s + std::to_string(i);
}
} // namespace
TEST(FlatTuple, Apply) {
using testing::internal::FlatTuple;
FlatTuple<int, std::string> tuple{testing::internal::FlatTupleConstructTag{},
5, "Hello"};
// Lambda.
EXPECT_TRUE(tuple.Apply([](int i, const std::string& s) -> bool {
return i == static_cast<int>(s.size());
}));
// Function.
EXPECT_EQ(tuple.Apply(AddIntToString), "Hello5");
// Mutating operations.
tuple.Apply([](int& i, std::string& s) {
++i;
s += s;
});
EXPECT_EQ(tuple.Get<0>(), 6);
EXPECT_EQ(tuple.Get<1>(), "HelloHello");
}
struct ConstructionCounting {
ConstructionCounting() { ++default_ctor_calls; }
~ConstructionCounting() { ++dtor_calls; }
ConstructionCounting(const ConstructionCounting&) { ++copy_ctor_calls; }
ConstructionCounting(ConstructionCounting&&) noexcept { ++move_ctor_calls; }
ConstructionCounting& operator=(const ConstructionCounting&) {
++copy_assignment_calls;
return *this;
}
ConstructionCounting& operator=(ConstructionCounting&&) noexcept {
++move_assignment_calls;
return *this;
}
static void Reset() {
default_ctor_calls = 0;
dtor_calls = 0;
copy_ctor_calls = 0;
move_ctor_calls = 0;
copy_assignment_calls = 0;
move_assignment_calls = 0;
}
static int default_ctor_calls;
static int dtor_calls;
static int copy_ctor_calls;
static int move_ctor_calls;
static int copy_assignment_calls;
static int move_assignment_calls;
};
int ConstructionCounting::default_ctor_calls = 0;
int ConstructionCounting::dtor_calls = 0;
int ConstructionCounting::copy_ctor_calls = 0;
int ConstructionCounting::move_ctor_calls = 0;
int ConstructionCounting::copy_assignment_calls = 0;
int ConstructionCounting::move_assignment_calls = 0;
TEST(FlatTuple, ConstructorCalls) {
using testing::internal::FlatTuple;
// Default construction.
ConstructionCounting::Reset();
{ FlatTuple<ConstructionCounting> tuple; }
EXPECT_EQ(ConstructionCounting::default_ctor_calls, 1);
EXPECT_EQ(ConstructionCounting::dtor_calls, 1);
EXPECT_EQ(ConstructionCounting::copy_ctor_calls, 0);
EXPECT_EQ(ConstructionCounting::move_ctor_calls, 0);
EXPECT_EQ(ConstructionCounting::copy_assignment_calls, 0);
EXPECT_EQ(ConstructionCounting::move_assignment_calls, 0);
// Copy construction.
ConstructionCounting::Reset();
{
ConstructionCounting elem;
FlatTuple<ConstructionCounting> tuple{
testing::internal::FlatTupleConstructTag{}, elem};
}
EXPECT_EQ(ConstructionCounting::default_ctor_calls, 1);
EXPECT_EQ(ConstructionCounting::dtor_calls, 2);
EXPECT_EQ(ConstructionCounting::copy_ctor_calls, 1);
EXPECT_EQ(ConstructionCounting::move_ctor_calls, 0);
EXPECT_EQ(ConstructionCounting::copy_assignment_calls, 0);
EXPECT_EQ(ConstructionCounting::move_assignment_calls, 0);
// Move construction.
ConstructionCounting::Reset();
{
FlatTuple<ConstructionCounting> tuple{
testing::internal::FlatTupleConstructTag{}, ConstructionCounting{}};
}
EXPECT_EQ(ConstructionCounting::default_ctor_calls, 1);
EXPECT_EQ(ConstructionCounting::dtor_calls, 2);
EXPECT_EQ(ConstructionCounting::copy_ctor_calls, 0);
EXPECT_EQ(ConstructionCounting::move_ctor_calls, 1);
EXPECT_EQ(ConstructionCounting::copy_assignment_calls, 0);
EXPECT_EQ(ConstructionCounting::move_assignment_calls, 0);
// Copy assignment.
// TODO(ofats): it should be testing assignment operator of FlatTuple, not its
// elements
ConstructionCounting::Reset();
{
FlatTuple<ConstructionCounting> tuple;
ConstructionCounting elem;
tuple.Get<0>() = elem;
}
EXPECT_EQ(ConstructionCounting::default_ctor_calls, 2);
EXPECT_EQ(ConstructionCounting::dtor_calls, 2);
EXPECT_EQ(ConstructionCounting::copy_ctor_calls, 0);
EXPECT_EQ(ConstructionCounting::move_ctor_calls, 0);
EXPECT_EQ(ConstructionCounting::copy_assignment_calls, 1);
EXPECT_EQ(ConstructionCounting::move_assignment_calls, 0);
// Move assignment.
// TODO(ofats): it should be testing assignment operator of FlatTuple, not its
// elements
ConstructionCounting::Reset();
{
FlatTuple<ConstructionCounting> tuple;
tuple.Get<0>() = ConstructionCounting{};
}
EXPECT_EQ(ConstructionCounting::default_ctor_calls, 2);
EXPECT_EQ(ConstructionCounting::dtor_calls, 2);
EXPECT_EQ(ConstructionCounting::copy_ctor_calls, 0);
EXPECT_EQ(ConstructionCounting::move_ctor_calls, 0);
EXPECT_EQ(ConstructionCounting::copy_assignment_calls, 0);
EXPECT_EQ(ConstructionCounting::move_assignment_calls, 1);
ConstructionCounting::Reset();
}
TEST(FlatTuple, ManyTypes) {
using testing::internal::FlatTuple;
......@@ -7439,22 +7750,7 @@ TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
}
// Tests ad_hoc_test_result().
class AdHocTestResultTest : public testing::Test {
protected:
static void SetUpTestSuite() {
FAIL() << "A failure happened inside SetUpTestSuite().";
}
};
TEST_F(AdHocTestResultTest, AdHocTestResultForTestSuiteShowsFailure) {
const testing::TestResult& test_result = testing::UnitTest::GetInstance()
->current_test_suite()
->ad_hoc_test_result();
EXPECT_TRUE(test_result.Failed());
}
TEST_F(AdHocTestResultTest, AdHocTestResultTestForUnitTestDoesNotShowFailure) {
TEST(AdHocTestResultTest, AdHocTestResultForUnitTestDoesNotShowFailure) {
const testing::TestResult& test_result =
testing::UnitTest::GetInstance()->ad_hoc_test_result();
EXPECT_FALSE(test_result.Failed());
......
......@@ -42,7 +42,7 @@ GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_"
EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
<testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*">
<testsuite name="PropertyOne" tests="1" failures="0" skipped="0" disabled="0" errors="0" time="*" timestamp="*">
<testcase name="TestSomeProperties" status="run" result="completed" time="*" timestamp="*" classname="PropertyOne">
<properties>
<property name="SetUpProp" value="1"/>
......@@ -56,7 +56,7 @@ EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
<testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*">
<testsuite name="PropertyTwo" tests="1" failures="0" skipped="0" disabled="0" errors="0" time="*" timestamp="*">
<testcase name="TestSomeProperties" status="run" result="completed" time="*" timestamp="*" classname="PropertyTwo">
<properties>
<property name="SetUpProp" value="2"/>
......
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