This predicate-formatter checks that 'results' contains a test part failure of the given type and that the failure message contains the given substring.
| 2091 | // failure of the given type and that the failure message contains the |
| 2092 | // given substring. |
| 2093 | AssertionResult HasOneFailure(const char* /* results_expr */, |
| 2094 | const char* /* type_expr */, |
| 2095 | const char* /* substr_expr */, |
| 2096 | const TestPartResultArray& results, |
| 2097 | TestPartResult::Type type, |
| 2098 | const string& substr) { |
| 2099 | const std::string expected(type == TestPartResult::kFatalFailure ? |
| 2100 | "1 fatal failure" : |
| 2101 | "1 non-fatal failure"); |
| 2102 | Message msg; |
| 2103 | if (results.size() != 1) { |
| 2104 | msg << "Expected: " << expected << "\n" |
| 2105 | << " Actual: " << results.size() << " failures"; |
| 2106 | for (int i = 0; i < results.size(); i++) { |
| 2107 | msg << "\n" << results.GetTestPartResult(i); |
| 2108 | } |
| 2109 | return AssertionFailure() << msg; |
| 2110 | } |
| 2111 | |
| 2112 | const TestPartResult& r = results.GetTestPartResult(0); |
| 2113 | if (r.type() != type) { |
| 2114 | return AssertionFailure() << "Expected: " << expected << "\n" |
| 2115 | << " Actual:\n" |
| 2116 | << r; |
| 2117 | } |
| 2118 | |
| 2119 | if (strstr(r.message(), substr.c_str()) == NULL) { |
| 2120 | return AssertionFailure() << "Expected: " << expected << " containing \"" |
| 2121 | << substr << "\"\n" |
| 2122 | << " Actual:\n" |
| 2123 | << r; |
| 2124 | } |
| 2125 | |
| 2126 | return AssertionSuccess(); |
| 2127 | } |
| 2128 | |
| 2129 | // The constructor of SingleFailureChecker remembers where to look up |
| 2130 | // test part results, what type of failure we expect, and what |
nothing calls this directly
no test coverage detected