diff options
-rw-r--r-- | 002test.cc | 3 | ||||
-rw-r--r-- | 003trace.cc | 17 | ||||
-rw-r--r-- | 050scenario.cc | 5 |
3 files changed, 21 insertions, 4 deletions
diff --git a/002test.cc b/002test.cc index f857c2a1..bf0611f2 100644 --- a/002test.cc +++ b/002test.cc @@ -77,8 +77,9 @@ void run_test(size_t i) { setup(); // End Test Setup (*Tests[i])(); + // End Test Teardown teardown(); - if (Passed) cerr << "."; + if (Passed) cerr << '.'; } bool is_integer(const string& s) { 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) { diff --git a/050scenario.cc b/050scenario.cc index 94166f91..d7ffda6f 100644 --- a/050scenario.cc +++ b/050scenario.cc @@ -150,6 +150,11 @@ void run_mu_scenario(const scenario& s) { bind_special_scenario_names(tmp.at(0)); transform_all(); run(tmp.front()); + if (Passed && ((!Hide_errors && trace_count("error") > 0) + || (!Hide_warnings && trace_count("warn") > 0))) { + Passed = false; + ++Num_failures; + } if (not_already_inside_test && Trace_stream) { teardown(); ofstream fout((Trace_dir+Trace_file).c_str()); |