From 030bdbed8524824319bbbc2b0a86163e185b96d9 Mon Sep 17 00:00:00 2001 From: Alex Williams Date: Sun, 29 Mar 2015 03:03:20 +0000 Subject: [PATCH] Small refactor: replace anonymous function with simpler eval --- CHANGELOG.md | 5 +++++ EXPLAIN.md | 12 +++++------- module.l | 2 +- unit.l | 6 ++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 562bba4..0ae15dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.5.1 (2015-03-29) + + * Small refactor: replace anonymous function with simpler eval + * Update EXPLAIN.md + ## 0.5.0 (2015-03-29) * Assertions now return T or NIL, for passed or failed tests diff --git a/EXPLAIN.md b/EXPLAIN.md index a3ade1d..36af0ba 100644 --- a/EXPLAIN.md +++ b/EXPLAIN.md @@ -161,15 +161,11 @@ The 1st argument (anonymous function) generates a random number between 1 and th It's crazy how that works. I'm not even sure how I came up with that. ```lisp -(de execute @ - (mapcar - '((N) (prin (align 3 (inc '*Counter)) ") ") (eval N)) - (randomize (rest)) ] +[de execute @ + (mapcar eval (randomize (rest) ] ``` -Once our list of tests is randomized, we run it through our favourite [mapcar](http://software-lab.de/doc/refM.html#mapcar) function which prints the test's number, stored in `*Counter`, aligned to 3 columns, and then evaluates (runs) the test using the infamous [eval](http://software-lab.de/doc/refE.html#eval). - -The `(align 3)` allows the test numbers to go from 1 to 999 without breaking the beautiful output. We can increase that when someone actually encounters that problem. +Once our list of tests is randomized, we run it through our favourite [mapcar](http://software-lab.de/doc/refM.html#mapcar) function which evaluates (runs) the test using the infamous [eval](http://software-lab.de/doc/refE.html#eval). > **Note:* Technically, assertions don't catch errors, so if your assertion were to throw an unhandled error, then the entire test suite would fail and ugly things will happen. In fact, your terminals colours might not even get reset. That's a good thing. You should handle your errors. @@ -188,6 +184,8 @@ This library introduces simple wrappers around those predicates, which then call This one is quite simple, all it does is check if `Expected` is equal to `Result`. +The `(passed)` and `(failed)` functions will return `T` or `NIL`, respectively, so these can be used within your own code as well, not only in the context of unit tests. + The [other assertions](https://github.com/aw/picolisp-unit/blob/master/README.md#assertions-table) are quite similar and seem to cover most test cases. I've considered adding opposite tests such as `refute`, but I've rarely found a need for them as there are alternate approaches. # The end diff --git a/module.l b/module.l index 5881439..e84787e 100644 --- a/module.l +++ b/module.l @@ -1,6 +1,6 @@ [de MODULE_INFO ("name" "unit") - ("version" "0.5.0") + ("version" "0.5.1") ("summary" "Unit Testing framework for PicoLisp") ("source" "https://github.com/aw/picolisp-unit.git") ("author" "Alexander Williams") diff --git a/unit.l b/unit.l index a30ece6..704a72f 100644 --- a/unit.l +++ b/unit.l @@ -136,10 +136,8 @@ # public -(de execute @ - (mapcar - '((N) (eval N)) - (randomize (rest)) ] +[de execute @ + (mapcar eval (randomize (rest) ] [de assert-equal (Expected Result Message) (if (= Expected Result)