[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [ANN] Shake 1.0 Released
- From: "Andre Carregal" <carregal@...>
- Date: Tue, 18 Dec 2007 19:34:39 -0200
Shake is a simple test engine for Lua that assumes that tests only use
standard assert() and print() calls:
http://shake.luaforge.net/
Before triggering any flame throwers, here is the Shake FAQ:
-----
Q: Why another test framework? We already have lunit and luaunit!
A: Because this one is transparent, meaning tests do not have to be
written for it. The idea is to be able to run any Lua test file out
there without any changes to the file.
Q: I insist. Why another framework?
A: Because now we have Leg and Leg is powerful. Most of the API in
xUnit is there because you can't get that info easily from standard
assertions, unless you macro expand them, which Shake does.
-----
A quick example from the Shake manual may show the difference between
Shake and other test frameworks. Let's say we have a test.lua file
like:
1 items = 10
2 -- checks the correct case
3 assert (items == 10, "this should not fail")
4
5 items = 20
6 -- checks an overflow case
7 assert (items == 10, "wrong number of items")
8
9 print("Verifying the total")
10 items = 10
11 total = 30
12 assert (items == total, "wrong total")
Executing this file with plain Lua would result in:
:~/workspace$ lua5.1 test.lua
lua5.1: test.lua:7: wrong number of items
stack traceback:
[C]: in function 'assert'
test.lua:7: in main chunk
[C]: ?
Most other test frameworks would report that the file has 3 tests and
2 of them failed, you can get that by redefining assert() to not generate
an errror. But if you use Shake instead, the output would be:
:~/workspace$ shake
---------------- test.lua failed! ----------------
-- checks an overflow case
#7 assert (items == 10, "wrong number of items")
items -> 20
Verifying the total
#12 assert (items == total, "wrong total")
items -> 10
total -> 30
_________________
Tests: 3
Failures: 2
Errors: 0
Note how information from print and comments is used to group
assertions and how Shake was able to inform the current values from
variables inside the assert call.
In order to do that, Shake depends on Leg for parsing the source code
so Shake can "macro-expand" assert calls into calls that pass the
whole assertion context for the Shake runner.
The point is that this is transparently done, so you can shake any
"standard" Lua test file and it should be able to check a lot of
things that a normal Lua execution would not be able to.
Shake offers a standard command line runner but also a CGILUa
application runner. There is still a lot to do in the Shake CGILua application,
but the current version may already serve as a simple example of how to use
the CGILua application model.
And last but not least, for those using LuaRocks 0.3.1 just type
"luarocks install shake" to install the command line runner. To
install the CGILua application please check the Shake manual.
Any feedback is welcome, including more material for the FAQ. :o)
André