Compares the name of each test with the user-specified filter to decide whether the test should be run, then records the result in each TestCase and TestInfo object. If shard_tests == true, further filters tests based on sharding variables in the environment - see http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide. Returns the number of tests that should run.
| 5937 | // http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide. |
| 5938 | // Returns the number of tests that should run. |
| 5939 | int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { |
| 5940 | const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ? |
| 5941 | Int32FromEnvOrDie(kTestTotalShards, -1) : -1; |
| 5942 | const Int32 shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ? |
| 5943 | Int32FromEnvOrDie(kTestShardIndex, -1) : -1; |
| 5944 | |
| 5945 | // num_runnable_tests are the number of tests that will |
| 5946 | // run across all shards (i.e., match filter and are not disabled). |
| 5947 | // num_selected_tests are the number of tests to be run on |
| 5948 | // this shard. |
| 5949 | int num_runnable_tests = 0; |
| 5950 | int num_selected_tests = 0; |
| 5951 | for (size_t i = 0; i < test_cases_.size(); i++) { |
| 5952 | TestCase* const test_case = test_cases_[i]; |
| 5953 | const std::string &test_case_name = test_case->name(); |
| 5954 | test_case->set_should_run(false); |
| 5955 | |
| 5956 | for (size_t j = 0; j < test_case->test_info_list().size(); j++) { |
| 5957 | TestInfo* const test_info = test_case->test_info_list()[j]; |
| 5958 | const std::string test_name(test_info->name()); |
| 5959 | // A test is disabled if test case name or test name matches |
| 5960 | // kDisableTestFilter. |
| 5961 | const bool is_disabled = |
| 5962 | internal::UnitTestOptions::MatchesFilter(test_case_name, |
| 5963 | kDisableTestFilter) || |
| 5964 | internal::UnitTestOptions::MatchesFilter(test_name, |
| 5965 | kDisableTestFilter); |
| 5966 | test_info->is_disabled_ = is_disabled; |
| 5967 | |
| 5968 | const bool matches_filter = |
| 5969 | internal::UnitTestOptions::FilterMatchesTest(test_case_name, |
| 5970 | test_name); |
| 5971 | test_info->matches_filter_ = matches_filter; |
| 5972 | |
| 5973 | const bool is_runnable = |
| 5974 | (GTEST_FLAG(also_run_disabled_tests) || !is_disabled) && |
| 5975 | matches_filter; |
| 5976 | |
| 5977 | const bool is_selected = is_runnable && |
| 5978 | (shard_tests == IGNORE_SHARDING_PROTOCOL || |
| 5979 | ShouldRunTestOnShard(total_shards, shard_index, |
| 5980 | num_runnable_tests)); |
| 5981 | |
| 5982 | num_runnable_tests += is_runnable; |
| 5983 | num_selected_tests += is_selected; |
| 5984 | |
| 5985 | test_info->should_run_ = is_selected; |
| 5986 | test_case->set_should_run(test_case->should_run() || is_selected); |
| 5987 | } |
| 5988 | } |
| 5989 | return num_selected_tests; |
| 5990 | } |
| 5991 | |
| 5992 | // Prints the given C-string on a single line by replacing all '\n' |
| 5993 | // characters with string "\\n". If the output takes more than |
nothing calls this directly
no test coverage detected