1
0
pretty/test/tests.lua

50 lines
1.3 KiB
Lua
Raw Normal View History

2016-12-28 23:51:07 +00:00
-- Util function
local function get_test_modules (test_folder_and_prefix)
local function string_split (str, sep)
local t, i = {}, 1
for str in string.gmatch(str, "([^".. (sep or '%s') .."]+)") do
t[#t+1] = str
end
return t
end
local function os_execute (command)
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()
return string_split(result)
end
local function get_test_filenames (dir_and_prefix)
return os_execute('ls '..dir_and_prefix)
end
local function load_test_modules (test_filenames)
local modules = {}
for _, filename in ipairs(test_filenames) do
local module = require(filename:sub(1,-5))
assert(type(module) == 'table', ('ERROR: Module "%s" did not return a Table value.'):format(filename))
modules[#modules+1] = module
end
return modules
end
local test_filenames = get_test_filenames(test_folder_and_prefix)
local test_modules = load_test_modules(test_filenames)
return test_modules
end
-- Load modules and run them
package.path = package.path .. ';./test/?.lua'
local TEST_SUITE = require("TestSuite").new('Pretty')
local modules = get_test_modules('test/test_*')
TEST_SUITE:addModules(modules)
TEST_SUITE:runTests()