This predicate-formatter checks that 'results' contains a test part failure of the given type and that the failure message contains the given substring.
| 2137 | // failure of the given type and that the failure message contains the |
| 2138 | // given substring. |
| 2139 | static AssertionResult HasOneFailure(const char* /* results_expr */, |
| 2140 | const char* /* type_expr */, |
| 2141 | const char* /* substr_expr */, |
| 2142 | const TestPartResultArray& results, |
| 2143 | TestPartResult::Type type, |
| 2144 | const std::string& substr) { |
| 2145 | const std::string expected(type == TestPartResult::kFatalFailure ? |
| 2146 | "1 fatal failure" : |
| 2147 | "1 non-fatal failure"); |
| 2148 | Message msg; |
| 2149 | if (results.size() != 1) { |
| 2150 | msg << "Expected: " << expected << "\n" |
| 2151 | << " Actual: " << results.size() << " failures"; |
| 2152 | for (int i = 0; i < results.size(); i++) { |
| 2153 | msg << "\n" << results.GetTestPartResult(i); |
| 2154 | } |
| 2155 | return AssertionFailure() << msg; |
| 2156 | } |
| 2157 | |
| 2158 | const TestPartResult& r = results.GetTestPartResult(0); |
| 2159 | if (r.type() != type) { |
| 2160 | return AssertionFailure() << "Expected: " << expected << "\n" |
| 2161 | << " Actual:\n" |
| 2162 | << r; |
| 2163 | } |
| 2164 | |
| 2165 | if (strstr(r.message(), substr.c_str()) == nullptr) { |
| 2166 | return AssertionFailure() << "Expected: " << expected << " containing \"" |
| 2167 | << substr << "\"\n" |
| 2168 | << " Actual:\n" |
| 2169 | << r; |
| 2170 | } |
| 2171 | |
| 2172 | return AssertionSuccess(); |
| 2173 | } |
| 2174 | |
| 2175 | // The constructor of SingleFailureChecker remembers where to look up |
| 2176 | // test part results, what type of failure we expect, and what |
nothing calls this directly
no test coverage detected