Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Unified Diff: tests/Test.h

Issue 694703005: When running DM, write test failures to json. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/Test.h
diff --git a/tests/Test.h b/tests/Test.h
index 6c85b32bce6d95204b1ac8e66d57676f4941281c..c505a043beb834c81221f14b13bf7408070bcf2c 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -20,6 +20,32 @@ namespace skiatest {
class Test;
+ struct Failure {
+ SkString fileName;
mtklein 2014/11/06 15:24:05 Given that you know filename and condition are goi
scroggo 2014/11/06 16:52:33 To be fair, someone *could* skip the macro and cre
+ int lineNo;
+ SkString condition;
+ SkString message;
+
+ // Helper to combine the failure message into one string.
+ static void GetFailureString(SkString* result, const Failure& failure) {
mtklein 2014/11/06 15:24:05 Seems like this is simpler as SkString getFailureS
scroggo 2014/11/06 16:52:33 Definitely simpler. FWIW, I almost made it an out
+ if (!result) {
+ return;
+ }
+ result->printf("%s:%d\t", failure.fileName.c_str(), failure.lineNo);
+ if (!failure.message.isEmpty()) {
+ if (!failure.condition.isEmpty()) {
+ result->appendf("%s: %s", failure.message.c_str(), failure.condition.c_str());
+ } else {
+ result->append(failure.message);
+ }
+ } else if (!failure.condition.isEmpty()) {
+ // Condition, but no message.
+ result->append(failure.condition);
+ }
+ }
+ };
+
+
class Reporter : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(Reporter)
@@ -28,7 +54,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 +63,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 +136,34 @@ 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 = { SkString(__FILE__), __LINE__, \
+ SkString(#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 = { SkString(__FILE__), __LINE__, \
+ SkString(#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 = { SkString(__FILE__), __LINE__, \
+ SkString(), \
mtklein 2014/11/06 15:24:05 Might want something like "<ERRORF>" or "unconditi
scroggo 2014/11/06 16:52:32 I'm not sure that adds any more information. The o
+ SkString(desc) }; \
+ r->reportFailed(failure); \
} while(0)
#define DEF_TEST(name, reporter) \
« dm/DMTestTask.h ('K') | « tests/GrTRecorderTest.cpp ('k') | tests/Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698