summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-06-16 22:47:13 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-06-16 22:47:13 +0000
commit63b4f32b442c767ebe54ec66aed8b65d9c0b6f5e (patch)
tree3a0d849ba9e72f411fbcc0b1b8f1acd880647736
parent9748de060f19f81fd9dd7ccabf2be4bb624237b5 (diff)
downloadgtest-63b4f32b442c767ebe54ec66aed8b65d9c0b6f5e.tar.gz
gtest-63b4f32b442c767ebe54ec66aed8b65d9c0b6f5e.tar.bz2
gtest-63b4f32b442c767ebe54ec66aed8b65d9c0b6f5e.tar.xz
Makes gtest report failures in ad hoc test assertions executed before RUN_ALL_TESTS().
git-svn-id: http://googletest.googlecode.com/svn/trunk@441 861a406c-534a-0410-8894-cb66d6ee9925
-rw-r--r--src/gtest-internal-inl.h8
-rw-r--r--src/gtest.cc4
-rw-r--r--test/gtest_environment_test.cc5
-rw-r--r--test/gtest_no_test_unittest.cc11
4 files changed, 21 insertions, 7 deletions
diff --git a/src/gtest-internal-inl.h b/src/gtest-internal-inl.h
index 9e63aed..c5608c9 100644
--- a/src/gtest-internal-inl.h
+++ b/src/gtest-internal-inl.h
@@ -754,9 +754,13 @@ class GTEST_API_ UnitTestImpl {
// doesn't apply there.)
int RunAllTests();
- // Clears the results of all tests, including the ad hoc test.
- void ClearResult() {
+ // Clears the results of all tests, except the ad hoc tests.
+ void ClearNonAdHocTestResult() {
ForEach(test_cases_, TestCase::ClearTestCaseResult);
+ }
+
+ // Clears the results of ad-hoc test assertions.
+ void ClearAdHocTestResult() {
ad_hoc_test_result_.Clear();
}
diff --git a/src/gtest.cc b/src/gtest.cc
index e136a18..cb2c34c 100644
--- a/src/gtest.cc
+++ b/src/gtest.cc
@@ -3999,7 +3999,9 @@ int UnitTestImpl::RunAllTests() {
// Repeats forever if the repeat count is negative.
const bool forever = repeat < 0;
for (int i = 0; forever || i != repeat; i++) {
- ClearResult();
+ // We want to preserve failures generated by ad-hoc test
+ // assertions executed before RUN_ALL_TESTS().
+ ClearNonAdHocTestResult();
const TimeInMillis start = GetTimeInMillis();
diff --git a/test/gtest_environment_test.cc b/test/gtest_environment_test.cc
index c939261..94ea318 100644
--- a/test/gtest_environment_test.cc
+++ b/test/gtest_environment_test.cc
@@ -35,6 +35,10 @@
#include <stdio.h>
#include <gtest/gtest.h>
+#define GTEST_IMPLEMENTATION_ 1 // Required for the next #include.
+#include "src/gtest-internal-inl.h"
+#undef GTEST_IMPLEMENTATION_
+
namespace testing {
GTEST_DECLARE_string_(filter);
}
@@ -123,6 +127,7 @@ int RunAllTests(MyEnvironment* env, FailureType failure) {
env->Reset();
env->set_failure_in_set_up(failure);
test_was_run = false;
+ testing::internal::GetUnitTestImpl()->ClearAdHocTestResult();
return RUN_ALL_TESTS();
}
diff --git a/test/gtest_no_test_unittest.cc b/test/gtest_no_test_unittest.cc
index afe2dc0..e09ca73 100644
--- a/test/gtest_no_test_unittest.cc
+++ b/test/gtest_no_test_unittest.cc
@@ -40,15 +40,18 @@ int main(int argc, char **argv) {
// An ad-hoc assertion outside of all tests.
//
- // This serves two purposes:
+ // This serves three purposes:
//
// 1. It verifies that an ad-hoc assertion can be executed even if
// no test is defined.
- // 2. We had a bug where the XML output won't be generated if an
+ // 2. It verifies that a failed ad-hoc assertion causes the test
+ // program to fail.
+ // 3. We had a bug where the XML output won't be generated if an
// assertion is executed before RUN_ALL_TESTS() is called, even
// though --gtest_output=xml is specified. This makes sure the
// bug is fixed and doesn't regress.
- EXPECT_EQ(1, 1);
+ EXPECT_EQ(1, 2);
- return RUN_ALL_TESTS();
+ // The above EXPECT_EQ() should cause RUN_ALL_TESTS() to return non-zero.
+ return RUN_ALL_TESTS() ? 0 : 1;
}