Closed gelisam closed 2 years ago
As far as example
goes, I agree that it's not great for a test suite, but I like it's current behavior for interactive programming (e.g. instead of a REPL).
Can we write check-equal?
as a macro? Something like:
(check-equal NAME PRED ACTUAL EXPECTED)
====>
(example (if (PRED ACTUAL EXPECTED) (success 'NAME) (failure 'NAME ACTUAL EXPECTED)))
with a suitable sum type for the success and failure constructors? I think this would yield readable output with a minimum of work, and it could later be made into something with an effect on failure.
I added two comments, each explaining what a macros does using a commented-out example of what code the macro expands to.
Doing so made me realize that the
(example <expr>)
form has two flaws. First, since the output is in the golden file, it is cumbersome for the reader to jump between the example and its output. I think I would prefer(example <expr> <expected-output>)
, similarly tocheck-equal?
.Second, if
(<macro> <args>)
outputs(f 1 2 3)
, then(example (<macro> <args>))
outputs the result of the call(f 1 2 3)
, not the code'(f 1 2 3)
. When giving an example of what a macro does, like I did in those two comments, showing the code is often more helpful. I think we should thus have a variant ofexample
which does that.