From e781c2a91c245bbbc3607b6b16498d99f14ea36b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 11 Jun 2021 07:17:49 -0700 Subject: tests: support testing for warnings. * tests/common.tl (error-to-sym): Catch warnings, and convert to :warning symbol. (vtest): Support new kinds of expected value: :warning. The test is satisfied if it throws a warning at expansion time or during evaluation. --- tests/common.tl | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'tests/common.tl') diff --git a/tests/common.tl b/tests/common.tl index f89d6ed8..82cefd48 100644 --- a/tests/common.tl +++ b/tests/common.tl @@ -1,15 +1,25 @@ (defmacro error-to-sym (expr) ^(catch ,expr - (error (cond) :error))) + (error (cond) :error) + (warning (cond) :warning))) (defmacro vtest (:env env expr expected) - (if (mequal expected :error '':error) + (if-match (quote @(as sym @(or :error :warning))) expected + (set expected sym)) + (if (mequal expected :error :warning :warnerror) (catch (let ((expr-expn (expand expr env))) - ^(ifa (not (equal (error-to-sym ,expr-expn) :error)) + ^(ifa (not (equal (error-to-sym ,expr-expn) ,expected)) (error "test case ~s failed: produced ~s; expected ~s" - ',expr it :error))) - (error (exc))) + ',expr it ,expected))) + (error (exc) + (if (eq expected :warning) + (error "test case ~s produced error during expansion, expected ~s" + expr expected))) + (warning (exc) + (if (eq expected :error) + (error "test case ~s warned during expansion, expected ~s" + expr expected)))) (let ((expr-expn (expand expr env)) (expval (gensym))) ^(let ((,expval ,expected)) -- cgit v1.2.3