about summary refs log tree commit diff stats
path: root/003trace.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-02-25 07:31:20 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-02-25 07:31:20 -0800
commitb5ab709c53d3f8464e6358678a3c57a1fc6e64b8 (patch)
tree3deb5d01142af3ad9c94771b3596adebc1609050 /003trace.cc
parenta3f420b61de52fe8cdfa3d90be36648c5913198d (diff)
downloadmu-b5ab709c53d3f8464e6358678a3c57a1fc6e64b8.tar.gz
2700 - fail tests on unexpected errors or warnings
Diffstat (limited to '003trace.cc')
-rw-r--r--003trace.cc17
1 files changed, 14 insertions, 3 deletions
diff --git a/003trace.cc b/003trace.cc
index df57c374..d6a60985 100644
--- a/003trace.cc
+++ b/003trace.cc
@@ -142,8 +142,8 @@ struct trace_stream {
     curr_depth = Max_depth;
   }
 
-  // Useful for debugging.
-  string readable_contents(string label) {  // missing label = everything
+  // useful for debugging
+  string readable_contents(string label) {  // empty label = show everything
     ostringstream output;
     label = trim(label);
     for (vector<trace_line>::iterator p = past_lines.begin(); p != past_lines.end(); ++p)
@@ -158,10 +158,20 @@ struct trace_stream {
 
 trace_stream* Trace_stream = NULL;
 
-// Top-level helper. IMPORTANT: can't nest.
+// Top-level helper. IMPORTANT: can't nest
 #define trace(...)  !Trace_stream ? cerr /*print nothing*/ : Trace_stream->stream(__VA_ARGS__)
+
+// Errors and warnings are special layers.
 #define raise  (!Trace_stream ? (tb_shutdown(),cerr) /*do print*/ : Trace_stream->stream(Warning_depth, "warn"))
 #define raise_error  (!Trace_stream ? (tb_shutdown(),cerr) /*do print*/ : Trace_stream->stream(Error_depth, "error"))
+// Inside tests, fail any tests that displayed (unexpected) errors.
+// Expected errors in tests should always be hidden and silently checked for.
+:(before "End Test Teardown")
+if (Passed && ((!Hide_errors && trace_count("error") > 0)
+                || (!Hide_warnings && trace_count("warn") > 0))) {
+  Passed = false;
+  ++Num_failures;
+}
 
 :(before "End Types")
 struct end {};
@@ -252,6 +262,7 @@ int trace_count(string label) {
 }
 
 int trace_count(string label, string line) {
+  if (!Trace_stream) return 0;
   long result = 0;
   for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
     if (label == p->label) {