2700 - fail tests on unexpected errors or warnings

This commit is contained in:
Kartik K. Agaram 2016-02-25 07:31:20 -08:00
parent a3f420b61d
commit b5ab709c53
3 changed files with 21 additions and 4 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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());