From 647e9a12b4fc86a54e98216464ec4a1ae5a83229 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 4 Jul 2013 13:11:16 -0700 Subject: [PATCH] 3064 - macros for checking warnings 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.) --- 001trace.cc | 9 +++++++++ 003tokenize.test.cc | 2 +- 004parenthesize.test.cc | 2 +- 014build.test.cc | 4 ++-- 021eval.test.cc | 6 +++--- 022primitives.test.cc | 4 ++-- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/001trace.cc b/001trace.cc index c6d2354d..397e90f9 100644 --- a/001trace.cc +++ b/001trace.cc @@ -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; } diff --git a/003tokenize.test.cc b/003tokenize.test.cc index 175cb2c6..f1bf53ab 100644 --- a/003tokenize.test.cc +++ b/003tokenize.test.cc @@ -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(); } diff --git a/004parenthesize.test.cc b/004parenthesize.test.cc index 283ead9f..5bdd9129 100644 --- a/004parenthesize.test.cc +++ b/004parenthesize.test.cc @@ -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() { diff --git a/014build.test.cc b/014build.test.cc index e05bf8c8..50f28c0b 100644 --- a/014build.test.cc +++ b/014build.test.cc @@ -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"); } diff --git a/021eval.test.cc b/021eval.test.cc index 9833fee3..66f7496b 100644 --- a/021eval.test.cc +++ b/021eval.test.cc @@ -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"); @@ -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"); @@ -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() { diff --git a/022primitives.test.cc b/022primitives.test.cc index 0761c105..0e944d74 100644 --- a/022primitives.test.cc +++ b/022primitives.test.cc @@ -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() { @@ -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() {