aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2016-12-05 11:35:07 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-12-05 18:30:46 +0000
commit287f6512f34d456b593ea030197925dfc5b15c65 (patch)
tree90b3e05666ec4d5cd1878204d9550f1988a4713c /tests
parent91db12d89c214235e24599f3ec18df2f952e99eb (diff)
Add a context stack to Reporter, for better error messages
Currently, just inject the Ganesh context type when running unit tests. Obviously, we can use this to supply other contextual information around tests that do many variations of configs, formats, etc... BUG=skia: Change-Id: Iab96632a92ec632e4d132bbcc17a91a8dd251e78 Reviewed-on: https://skia-review.googlesource.com/5565 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Test.h39
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/Test.h b/tests/Test.h
index ea10cdf7e3..8b60039da0 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -44,10 +44,47 @@ public:
virtual bool allowExtendedTest() const;
virtual bool verbose() const;
virtual void* stats() const { return nullptr; }
+
+ void reportFailedWithContext(const skiatest::Failure& f) {
+ SkString fullMessage = f.message;
+ if (!fContextStack.empty()) {
+ fullMessage.append(" [");
+ for (int i = 0; i < fContextStack.count(); ++i) {
+ if (i > 0) {
+ fullMessage.append(", ");
+ }
+ fullMessage.append(fContextStack[i]);
+ }
+ fullMessage.append("]");
+ }
+ this->reportFailed(skiatest::Failure(f.fileName, f.lineNo, f.condition, fullMessage));
+ }
+ void push(const SkString& message) {
+ fContextStack.push_back(message);
+ }
+ void pop() {
+ fContextStack.pop_back();
+ }
+
+private:
+ SkTArray<SkString> fContextStack;
};
#define REPORT_FAILURE(reporter, cond, message) \
- reporter->reportFailed(skiatest::Failure(__FILE__, __LINE__, cond, message))
+ reporter->reportFailedWithContext(skiatest::Failure(__FILE__, __LINE__, cond, message))
+
+class ReporterContext : SkNoncopyable {
+public:
+ ReporterContext(Reporter* reporter, const SkString& message) : fReporter(reporter) {
+ fReporter->push(message);
+ }
+ ~ReporterContext() {
+ fReporter->pop();
+ }
+
+private:
+ Reporter* fReporter;
+};
typedef void (*TestProc)(skiatest::Reporter*, sk_gpu_test::GrContextFactory*);