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 <norman@njclarke.com> wrote:
> http://github.com/norman/telescope
> 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
  end
  after do
    -- tear down
  end
  context "A nested context" do
    test "A test" do
      assert_not_equal("ham", "cheese")
    end
    context "Another nested context" do
      test "Another test" do
        assert_greater_than(2, 1)
      end
    end
  end
  test "A test in the top-level context" do
    assert_equal(3, 1)
  end
end

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:

name=$1
tlua -lmacro $name.lua
shift
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.