silentbicycle / lunatest

xUnit-style + randomized unit testing framework for Lua (and C projects using Lua, etc.)
84 stars 23 forks source link

is_test_key() #22

Closed AndreasMatthias closed 4 years ago

AndreasMatthias commented 9 years ago

How do you customize is_test_key() correctly?

I've tried the following which doesn't work:

lt = require 'lunatest'

function foo_1 ()
   lt.assert_true(1==1)
end

function lt.is_test_key (k)
   return type(k) == "string" and k:match("^foo.*")
end

lt.run()

To make this work I would have to patch lunatest as follows.

--- lunatest.lua.orig   2015-10-30 19:46:15.479191332 +0100
+++ lunatest.lua    2015-10-30 19:48:12.363187108 +0100
@@ -560,7 +560,7 @@
    local ts = {}
    if type(mod) == "table" then
        for k,v in pairs(mod) do
-           if is_test_key(k) and type(v) == "function" then
+           if lunatest.is_test_key(k) and type(v) == "function" then
                ts[k] = v
            end
        end