Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
682c89f7
Commit
682c89f7
authored
Jun 16, 2010
by
zhanyong.wan
Browse files
Makes gtest report failures in ad hoc test assertions executed before RUN_ALL_TESTS().
parent
985a3036
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
7 deletions
+21
-7
src/gtest-internal-inl.h
src/gtest-internal-inl.h
+6
-2
src/gtest.cc
src/gtest.cc
+3
-1
test/gtest_environment_test.cc
test/gtest_environment_test.cc
+5
-0
test/gtest_no_test_unittest.cc
test/gtest_no_test_unittest.cc
+7
-4
No files found.
src/gtest-internal-inl.h
View file @
682c89f7
...
...
@@ -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 test
s
.
void
Clear
NonAdHocTest
Result
()
{
ForEach
(
test_cases_
,
TestCase
::
ClearTestCaseResult
);
}
// Clears the results of ad-hoc test assertions.
void
ClearAdHocTestResult
()
{
ad_hoc_test_result_
.
Clear
();
}
...
...
src/gtest.cc
View file @
682c89f7
...
...
@@ -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
();
...
...
test/gtest_environment_test.cc
View file @
682c89f7
...
...
@@ -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
();
}
...
...
test/gtest_no_test_unittest.cc
View file @
682c89f7
...
...
@@ -40,15 +40,18 @@ int main(int argc, char **argv) {
// An ad-hoc assertion outside of all tests.
//
// This serves t
wo
purposes:
// This serves t
hree
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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment