-- running the tests and examples
require 'pl'
local lfs = require 'lfs'

-- get the Lua command-line used to invoke this script
local cmd = app.lua()

if arg[1] == "--luacov" then
    cmd = cmd..' -lluacov'
end

local D = path.dirname(arg[0])
print('Running tests in',D)

function do_lua_files ()
    for _,f in ipairs(dir.getfiles('.','*.lua')) do
        print(cmd..' '..f)
        local res = utils.execute(cmd..' '..f)
        if not res then
            print ('process failed with non-zero result: '..f)
            os.exit(1)
        end
    end
end

lfs.chdir(D)
do_lua_files()
