Chromium Code Reviews| Index: tests/Test.h |
| diff --git a/tests/Test.h b/tests/Test.h |
| index 6c85b32bce6d95204b1ac8e66d57676f4941281c..3fef73f0cbf1e660da9dff8382f5e69a1e5aafef 100644 |
| --- a/tests/Test.h |
| +++ b/tests/Test.h |
| @@ -20,6 +20,43 @@ namespace skiatest { |
| class Test; |
| + /** |
| + * Information about a single failure from a Test. |
| + * |
| + * Not intended to be created/modified directly. To create one, use one of |
| + * |
| + * REPORTER_ASSERT |
| + * REPORTER_ASSERT_MESSAGE |
| + * ERRORF |
| + * |
| + * described in more detail further down in this file. |
| + */ |
| + struct Failure { |
| + const char* fileName; |
| + int lineNo; |
| + const char* condition; |
| + SkString message; |
| + |
| + // Helper to combine the failure info into one string. |
| + void getFailureString(SkString* result) const { |
| + if (!result) { |
| + return; |
| + } |
| + result->printf("%s:%d\t", fileName, lineNo); |
| + if (!message.isEmpty()) { |
| + if (condition != NULL) { |
| + result->appendf("%s: %s", message.c_str(), condition); |
| + } else { |
| + result->append(message); |
| + } |
| + } else if (condition != NULL) { |
| + // Condition, but no message. |
| + result->append(condition); |
| + } |
| + } |
| + }; |
| + |
| + |
| class Reporter : public SkRefCnt { |
| public: |
| SK_DECLARE_INST_COUNT(Reporter) |
| @@ -28,7 +65,7 @@ namespace skiatest { |
| int countTests() const { return fTestCount; } |
| void startTest(Test*); |
| - void reportFailed(const SkString& desc); |
| + void reportFailed(const Failure&); |
| void endTest(Test*); |
| virtual bool allowExtendedTest() const { return false; } |
| @@ -37,7 +74,7 @@ namespace skiatest { |
| protected: |
| virtual void onStart(Test*) {} |
| - virtual void onReportFailed(const SkString& desc) {} |
| + virtual void onReportFailed(const Failure&) {} |
| virtual void onEnd(Test*) {} |
| private: |
| @@ -110,31 +147,31 @@ namespace skiatest { |
| } |
| */ |
| -#define REPORTER_ASSERT(r, cond) \ |
| - do { \ |
| - if (!(cond)) { \ |
| - SkString desc; \ |
| - desc.printf("%s:%d\t%s", __FILE__, __LINE__, #cond); \ |
| - r->reportFailed(desc); \ |
| - } \ |
| +#define REPORTER_ASSERT(r, cond) \ |
| + do { \ |
| + if (!(cond)) { \ |
| + skiatest::Failure failure = { __FILE__, __LINE__, \ |
| + #cond, SkString() }; \ |
| + r->reportFailed(failure); \ |
| + } \ |
| } while(0) |
| -#define REPORTER_ASSERT_MESSAGE(r, cond, message) \ |
| - do { \ |
| - if (!(cond)) { \ |
| - SkString desc; \ |
| - desc.printf("%s:%d\t%s: %s", __FILE__, __LINE__, \ |
| - message, #cond); \ |
| - r->reportFailed(desc); \ |
| - } \ |
| +#define REPORTER_ASSERT_MESSAGE(r, cond, message) \ |
| + do { \ |
| + if (!(cond)) { \ |
| + skiatest::Failure failure = { __FILE__, __LINE__, \ |
| + #cond, SkString(message) }; \ |
| + r->reportFailed(failure); \ |
| + } \ |
| } while(0) |
| -#define ERRORF(reporter, ...) \ |
| - do { \ |
| - SkString desc; \ |
| - desc.printf("%s:%d\t", __FILE__, __LINE__); \ |
| - desc.appendf(__VA_ARGS__) ; \ |
| - (reporter)->reportFailed(desc); \ |
| +#define ERRORF(r, ...) \ |
| + do { \ |
| + SkString desc; \ |
| + desc.appendf(__VA_ARGS__) ; \ |
| + skiatest::Failure failure = { __FILE__, __LINE__, \ |
| + NULL, SkString(desc) }; \ |
|
mtklein
2014/11/06 17:46:54
Consider "" instead of NULL here, so we never have
scroggo
2014/11/06 20:29:32
Done.
|
| + r->reportFailed(failure); \ |
| } while(0) |
| #define DEF_TEST(name, reporter) \ |