blob: f84b453baf76350727ffa40ce657830e74a2df64 (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
import("core.base.option")
import("test_utils.test_assert")
import("test_utils.print_error")
import("test_utils.build", { alias = "test_build" })
function main(script)
if os.isdir(script) then
script = path.join(script, "test.lua")
end
script = path.absolute(script)
assert(path.filename(script) == "test.lua")
assert(os.isfile(script))
-- disable statistics
os.setenv("XMAKE_STATS", "false")
-- init test context
local context =
{
filename = script
}
context = test_assert(context)
function context:build(argv)
test_build(argv)
end
local root = path.directory(script)
local verbose = option.get("verbose") or option.get("diagnosis")
-- trace
cprint(">> testing %s ...", path.relative(root))
-- enter script directory
local old_dir = os.cd(root)
-- get test functions
local data = import("test", { anonymous = true })
if data.main then
-- ignore everthing when we found a main function
data = { test_main = data.main }
end
-- run test
local succeed_count = 0
for k, v in pairs(data) do
if k:startswith("test") and type(v) == "function" then
if verbose then print(">> running %s ...", k) end
context.func = v
context.funcname = k
try
{
function ()
v(context)
end,
catch
{
function (error)
if not error:find("aborting because of ") then
print_error(error, v, "unhandled error")
else
raise(error)
end
end
}
}
succeed_count = succeed_count + 1
end
end
if verbose then print(">> finished %d test method(s) ...", succeed_count) end
-- leave script directory
os.cd(old_dir)
end
|