lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Wed, Oct 13, 2010 at 3:24 PM, Norman Clarke <> wrote:
> Your feedback would be very welcome!

Continuing the discussion we were having on luarocks-l, I think
writing tests is a great use case for Lua as a DSL, via some
preprocessor such as the token-filter patch or Metalua. For instance,
the example given above can be written like so using (e.g.) LuaMacro:

context "A context" do
  before do
    -- setup
  after do
    -- tear down
  context "A nested context" do
    test "A test" do
      assert_not_equal("ham", "cheese")
    context "Another nested context" do
      test "Another test" do
        assert_greater_than(2, 1)
  test "A test in the top-level context" do
    assert_equal(3, 1)

OK, this is no longer standard Lua, which _is_ an issue if this is
application code. But (as lhf always points out) a token-filter Lua
can be used as a compiler (like Metalua) which generates the code to
be executed by the regular Lua executable.

Here would be a typical launcher script for separate compile-run steps:

tlua -lmacro $name.lua
lua $name.luac $*

We could go further, and replace verbose things like
assert_greater_than by pseudo-expressions like:

! (x > y)

The important thing about designing DSLs is knowing when to stop ;)

steve d.