Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

Commit

Permalink
3064 - macros for checking warnings
Browse files Browse the repository at this point in the history
We sometimes now print extra warnings during teardown, but that's
preferable to hiding a warning the one time we should show it.

(Ideally we'd have levels of warnings.)
  • Loading branch information
akkartik committed Jul 4, 2013
1 parent 0d7784e commit 647e9a1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
9 changes: 9 additions & 0 deletions 001trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ int trace_count(string layer, int frame, string line) {
return result;
}

#define CHECK_TRACE_WARNS() CHECK(trace_count("warn") > 0)
#define CHECK_TRACE_DOESNT_WARN() if (trace_count("warn") > 0) { \
++Num_failures; \
cerr << "\nF " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): unexpected warnings\n"; \
DUMP("warn"); \
Passed = false; \
return; \
}

bool trace_doesnt_contain(string layer, string line) {
return trace_count(layer, line) == 0;
}
Expand Down
2 changes: 1 addition & 1 deletion 003tokenize.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ void test_tokenize_handles_sexpr() {
void test_quote_misuse_warns() {
Hide_warnings = true;
read_all("' a");
CHECK_EQ(trace_count("warn"), 1);
CHECK_TRACE_WARNS();
}
2 changes: 1 addition & 1 deletion 004parenthesize.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void test_parenthesize_errors_on_unbalanced_closed_paren() {
Hide_warnings = true;
indent_sensitive_stream in(")");
next_expr(in);
CHECK_EQ(trace_count("warn"), 1);
CHECK_TRACE_WARNS();
}

void test_parenthesize_handles_early_paren() {
Expand Down
4 changes: 2 additions & 2 deletions 014build.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ void test_build_handles_float() {
void test_build_warns_on_ambiguous_float() {
Hide_warnings = true;
read_all("-.4");
CHECK_EQ(trace_count("warn"), 1);
CHECK_TRACE_WARNS();
CHECK_TRACE_CONTENTS("cell", "float: -0.4");
}

void test_build_creates_floats_on_overflow() {
Hide_warnings = true;
read_all("100000000000000000000");
CHECK_EQ(trace_count("warn"), 1);
CHECK_TRACE_WARNS();
CHECK_TRACE_CONTENTS("cell", "float: 1e+20");
}

Expand Down
6 changes: 3 additions & 3 deletions 021eval.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ void test_eval_splice_on_macros_with_backquote() {
Hide_warnings = true;
run("m @args");
CHECK_TRACE_TOP("eval", "=> (a ... b)"); // spliced args override quoted params
CHECK_EQ(trace_count("warn"), 0);
CHECK_TRACE_DOESNT_WARN();
end_dynamic_scope("args");
end_dynamic_scope("b");
end_dynamic_scope("a");
Expand All @@ -429,7 +429,7 @@ void test_eval_splice_on_backquoteless_macros_warns() {
run("args <- '(a b)");
Hide_warnings = true;
run("m @args");
CHECK_EQ(trace_count("warn"), 1);
CHECK_TRACE_WARNS();
end_dynamic_scope("args");
end_dynamic_scope("b");
end_dynamic_scope("a");
Expand Down Expand Up @@ -601,7 +601,7 @@ void test_eval_handles_quoted_as_params() {
void test_eval_warns_on_unary_as() {
Hide_warnings = true;
run("((fn (| a) 3) 1 2)");
CHECK_EQ(trace_count("warn"), 1);
CHECK_TRACE_WARNS();
}

void test_eval_binds_missing_as_params_to_nil() {
Expand Down
4 changes: 2 additions & 2 deletions 022primitives.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void test_assign_to_non_sym_warns() {
trace("test") << "<-";
Hide_warnings = true;
run("(<- 3 nil)");
CHECK_EQ(trace_count("warn"), 1);
CHECK_TRACE_WARNS();
}

void test_assign_lexical_var() {
Expand Down Expand Up @@ -143,7 +143,7 @@ void test_equal_handles_float_vs_nil() {
Hide_warnings = true;
run("(nil = 1.5)");
CHECK_TRACE_TOP("eval", "=> nil");
CHECK_EQ(trace_count("warn"), 0);
CHECK_TRACE_DOESNT_WARN();
}

void test_eval_handles_eval() {
Expand Down

0 comments on commit 647e9a1

Please sign in to comment.