aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-04-24 20:27:29 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-04-24 20:27:29 +0000
commitfa2b06c52fa3ffb1909ed8b928e106292609cfcb (patch)
tree9641a37117afa67d303e37434a6b1810dee190f9 /src
parentf2d0d0e3d56794855d1e9a1f157457b7225e8c88 (diff)
downloadgoogletest-fa2b06c52fa3ffb1909ed8b928e106292609cfcb.tar.gz
googletest-fa2b06c52fa3ffb1909ed8b928e106292609cfcb.tar.bz2
googletest-fa2b06c52fa3ffb1909ed8b928e106292609cfcb.zip
Makes --gtest_list_tests honor the test filter (by Jay Campan).
Diffstat (limited to 'src')
-rw-r--r--src/gtest-internal-inl.h12
-rw-r--r--src/gtest.cc47
2 files changed, 39 insertions, 20 deletions
diff --git a/src/gtest-internal-inl.h b/src/gtest-internal-inl.h
index 2a90edac..26d1bd1d 100644
--- a/src/gtest-internal-inl.h
+++ b/src/gtest-internal-inl.h
@@ -621,6 +621,12 @@ class TestInfoImpl {
// Sets the is_disabled member.
void set_is_disabled(bool is) { is_disabled_ = is; }
+ // Returns true if this test matches the filter specified by the user.
+ bool matches_filter() const { return matches_filter_; }
+
+ // Sets the matches_filter member.
+ void set_matches_filter(bool matches) { matches_filter_ = matches; }
+
// Returns the test case name.
const char* test_case_name() const { return test_case_name_.c_str(); }
@@ -667,6 +673,8 @@ class TestInfoImpl {
const TypeId fixture_class_id_; // ID of the test fixture class
bool should_run_; // True iff this test should run
bool is_disabled_; // True iff this test is disabled
+ bool matches_filter_; // True if this test matches the
+ // user-specified filter.
internal::TestFactoryBase* const factory_; // The factory that creates
// the test object
@@ -1164,8 +1172,8 @@ class UnitTestImpl {
// Returns the number of tests that should run.
int FilterTests(ReactionToSharding shard_tests);
- // Lists all the tests by name.
- void ListAllTests();
+ // Prints the names of the tests matching the user-specified filter flag.
+ void ListTestsMatchingFilter();
const TestCase* current_test_case() const { return current_test_case_; }
TestInfo* current_test_info() { return current_test_info_; }
diff --git a/src/gtest.cc b/src/gtest.cc
index 6e01c1be..4a1b21f9 100644
--- a/src/gtest.cc
+++ b/src/gtest.cc
@@ -2172,6 +2172,9 @@ const char* TestInfo::comment() const {
// Returns true if this test should run.
bool TestInfo::should_run() const { return impl_->should_run(); }
+// Returns true if this test matches the user-specified filter.
+bool TestInfo::matches_filter() const { return impl_->matches_filter(); }
+
// Returns the result of the test.
const internal::TestResult* TestInfo::result() const { return impl_->result(); }
@@ -3297,8 +3300,8 @@ void UnitTest::AddTestPartResult(TestPartResultType result_type,
ReportTestPartResult(result);
if (result_type != TPRT_SUCCESS) {
- // gunit_break_on_failure takes precedence over
- // gunit_throw_on_failure. This allows a user to set the latter
+ // gtest_break_on_failure takes precedence over
+ // gtest_throw_on_failure. This allows a user to set the latter
// in the code (perhaps in order to use Google Test assertions
// with another testing framework) and specify the former on the
// command line for debugging.
@@ -3591,13 +3594,6 @@ int UnitTestImpl::RunAllTests() {
// protocol.
internal::WriteToShardStatusFileIfNeeded();
- // Lists all the tests and exits if the --gtest_list_tests
- // flag was specified.
- if (GTEST_FLAG(list_tests)) {
- ListAllTests();
- return 0;
- }
-
// True iff we are in a subprocess for running a thread-safe-style
// death test.
bool in_subprocess_for_death_test = false;
@@ -3618,6 +3614,13 @@ int UnitTestImpl::RunAllTests() {
? HONOR_SHARDING_PROTOCOL
: IGNORE_SHARDING_PROTOCOL) > 0;
+ // List the tests and exit if the --gtest_list_tests flag was specified.
+ if (GTEST_FLAG(list_tests)) {
+ // This must be called *after* FilterTests() has been called.
+ ListTestsMatchingFilter();
+ return 0;
+ }
+
// True iff at least one test has failed.
bool failed = false;
@@ -3808,10 +3811,14 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
kDisableTestFilter);
test_info->impl()->set_is_disabled(is_disabled);
- const bool is_runnable =
- (GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
+ const bool matches_filter =
internal::UnitTestOptions::FilterMatchesTest(test_case_name,
test_name);
+ test_info->impl()->set_matches_filter(matches_filter);
+
+ const bool is_runnable =
+ (GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
+ matches_filter;
const bool is_selected = is_runnable &&
(shard_tests == IGNORE_SHARDING_PROTOCOL ||
@@ -3828,23 +3835,26 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
return num_selected_tests;
}
-// Lists all tests by name.
-void UnitTestImpl::ListAllTests() {
+// Prints the names of the tests matching the user-specified filter flag.
+void UnitTestImpl::ListTestsMatchingFilter() {
for (const internal::ListNode<TestCase*>* test_case_node = test_cases_.Head();
test_case_node != NULL;
test_case_node = test_case_node->next()) {
const TestCase* const test_case = test_case_node->element();
-
- // Prints the test case name following by an indented list of test nodes.
- printf("%s.\n", test_case->name());
+ bool printed_test_case_name = false;
for (const internal::ListNode<TestInfo*>* test_info_node =
test_case->test_info_list().Head();
test_info_node != NULL;
test_info_node = test_info_node->next()) {
const TestInfo* const test_info = test_info_node->element();
-
- printf(" %s\n", test_info->name());
+ if (test_info->matches_filter()) {
+ if (!printed_test_case_name) {
+ printed_test_case_name = true;
+ printf("%s.\n", test_case->name());
+ }
+ printf(" %s\n", test_info->name());
+ }
}
}
fflush(stdout);
@@ -3941,6 +3951,7 @@ TestInfoImpl::TestInfoImpl(TestInfo* parent,
fixture_class_id_(fixture_class_id),
should_run_(false),
is_disabled_(false),
+ matches_filter_(false),
factory_(factory) {
}