summaryrefslogtreecommitdiff
path: root/tests/test.lua
blob: 2f67ba416d8ca0b9e7fb78ed7b581200cc8c2a93 (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
-- imports
import("core.project.task")

-- run test with the given name
function _run_test(name)

    -- find the test script
    for _, script in ipairs(os.files(path.join(os.scriptdir(), "**", name, "test.lua"))) do

        -- trace
        print("testing %s ...", script)

        -- enter script directory
        os.cd(path.directory(script))

        -- run test
        task.run("lua", {script = path.filename(script)})
        break
    end
end

-- main entry
function main(name)

    -- run the given test
    if name then
        return _run_test(name)
    end

    -- run all tests
    for _, script in ipairs(os.files(path.join(os.scriptdir(), "**", "test.lua"))) do

        -- trace
        print("testing %s ...", script)

        -- enter script directory
        local oldir = os.cd(path.directory(script))

        -- run test
        task.run("lua", {script = path.filename(script)})

        -- leave script directory
        os.cd(oldir)
    end
end