This predicate-formatter checks that 'results' contains a test part failure of the given type and that the failure message contains the given substring.
| 2111 | // failure of the given type and that the failure message contains the |
| 2112 | // given substring. |
| 2113 | AssertionResult HasOneFailure(const char* /* results_expr */, |
| 2114 | const char* /* type_expr */, |
| 2115 | const char* /* substr_expr */, |
| 2116 | const TestPartResultArray& results, |
| 2117 | TestPartResult::Type type, |
| 2118 | const string& substr) { |
| 2119 | const std::string expected(type == TestPartResult::kFatalFailure ? |
| 2120 | "1 fatal failure" : |
| 2121 | "1 non-fatal failure"); |
| 2122 | Message msg; |
| 2123 | if (results.size() != 1) { |
| 2124 | msg << "Expected: " << expected << "\n" |
| 2125 | << " Actual: " << results.size() << " failures"; |
| 2126 | for (int i = 0; i < results.size(); i++) { |
| 2127 | msg << "\n" << results.GetTestPartResult(i); |
| 2128 | } |
| 2129 | return AssertionFailure() << msg; |
| 2130 | } |
| 2131 | |
| 2132 | const TestPartResult& r = results.GetTestPartResult(0); |
| 2133 | if (r.type() != type) { |
| 2134 | return AssertionFailure() << "Expected: " << expected << "\n" |
| 2135 | << " Actual:\n" |
| 2136 | << r; |
| 2137 | } |
| 2138 | |
| 2139 | if (strstr(r.message(), substr.c_str()) == NULL) { |
| 2140 | return AssertionFailure() << "Expected: " << expected << " containing \"" |
| 2141 | << substr << "\"\n" |
| 2142 | << " Actual:\n" |
| 2143 | << r; |
| 2144 | } |
| 2145 | |
| 2146 | return AssertionSuccess(); |
| 2147 | } |
| 2148 | |
| 2149 | // The constructor of SingleFailureChecker remembers where to look up |
| 2150 | // test part results, what type of failure we expect, and what |
nothing calls this directly
no test coverage detected