summaryrefslogtreecommitdiff
path: root/tests/run.lua
blob: f56933f3bfd39de7485fb3a60054b5aef91e1a3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- imports
import("core.base.task")
import("core.base.option")
import("runner", {rootdir = os.scriptdir()})

function _run_test(script, opt)
    runner(script, opt)
end

-- run test with the given name
function _run_test_filter(name)
    local tests = {}
    local root = path.absolute(os.scriptdir())
    for _, script in ipairs(os.files(path.join(root, "**", name, "**", "test.lua"))) do
        if not script:find(".xmake", 1, true) then
            table.insert(tests, path.absolute(script))
        end
    end
    for _, script in ipairs(os.files(path.join(root, name, "**", "test.lua"))) do
        if not script:find(".xmake", 1, true) then
            table.insert(tests, path.absolute(script))
        end
    end
    for _, script in ipairs(os.files(path.join(root, "**", name, "test.lua"))) do
        table.insert(tests, path.absolute(script))
    end
    for _, script in ipairs(os.files(path.join(root, name, "test.lua"))) do
        table.insert(tests, path.absolute(script))
    end

    tests = table.unique(tests)
    if #tests == 0 then
        utils.warning("no test have run, please check your filter .. (%s)", name)
    else
        cprint("> %d test(s) found", #tests)
        if option.get("diagnosis") then
            for _, v in ipairs(tests) do
                cprint(">     %s", v)
            end
        end
        for i, v in ipairs(tests) do
            _run_test(v, {index = i, total = #tests})
        end
        cprint("> %d test(s) succeed", #tests)
    end
end

function main(name)
    return _run_test_filter(name or "/")
end