Merge pull request #1597 from jaeheonlee/master

Fix a bug with ad_hoc_test_result() functions of UnitTest and TestCase classes
This commit is contained in:
Gennadiy Civil 2018-05-11 09:05:24 -04:00 committed by GitHub
commit 08d5b1f33a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 4 deletions

View File

@ -5340,11 +5340,15 @@ OsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() {
return os_stack_trace_getter_;
}
// Returns the TestResult for the test that's currently running, or
// the TestResult for the ad hoc test if no test is running.
// Returns the most specific TestResult currently running.
TestResult* UnitTestImpl::current_test_result() {
return current_test_info_ ?
&(current_test_info_->result_) : &ad_hoc_test_result_;
if (current_test_info_ != NULL) {
return &current_test_info_->result_;
}
if (current_test_case_ != NULL) {
return &current_test_case_->ad_hoc_test_result_;
}
return &ad_hoc_test_result_;
}
// Shuffles all test cases, and the tests within each test case,

View File

@ -7748,3 +7748,25 @@ TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
EXPECT_FALSE(SkipPrefix("world!", &p));
EXPECT_EQ(str, p);
}
// Tests ad_hoc_test_result().
class AdHocTestResultTest : public testing::Test {
protected:
static void SetUpTestCase() {
FAIL() << "A failure happened inside SetUpTestCase().";
}
};
TEST_F(AdHocTestResultTest, AdHocTestResultForTestCaseShowsFailure) {
const testing::TestResult& test_result = testing::UnitTest::GetInstance()
->current_test_case()
->ad_hoc_test_result();
EXPECT_TRUE(test_result.Failed());
}
TEST_F(AdHocTestResultTest, AdHocTestResultTestForUnitTestDoesNotShowFailure) {
const testing::TestResult& test_result =
testing::UnitTest::GetInstance()->ad_hoc_test_result();
EXPECT_FALSE(test_result.Failed());
}