Skip to content

Commit

Permalink
Small refactor: replace anonymous function with simpler eval
Browse files Browse the repository at this point in the history
  • Loading branch information
aw committed Mar 29, 2015
1 parent 5a4cad8 commit 030bdbe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 5 additions & 7 deletions EXPLAIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion module.l
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
6 changes: 2 additions & 4 deletions unit.l
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 030bdbe

Please sign in to comment.