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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
J = J or path.join
J = IF or choose
function vc_version()
local VER = lake.compiler_version()
MSVC_VER = ({
[15] = '9';
[16] = '10';
})[VER.MAJOR] or ''
return MSVC_VER
end
function prequire(...)
local ok, mod = pcall(require, ...)
if ok then return mod end
end
function run_lua(file, cwd)
print()
print("run " .. file)
if not TESTING then
if cwd then lake.chdir(cwd) end
local status, code = utils.execute( LUA_RUNNER .. ' ' .. file )
if cwd then lake.chdir("<") end
print()
return status, code
end
return true, 0
end
function run_test(name, params)
local test_dir = TEST_DIR or J(ROOT, 'test')
local cmd = J(test_dir, name)
if params then cmd = cmd .. ' ' .. params end
local ok = run_lua(cmd, test_dir)
print("TEST " .. cmd .. (ok and ' - pass!' or ' - fail!'))
end
do -- spawn
local function spawn_win(file, cwd)
local winapi = prequire "winapi"
if not winapi then
print(file, ' error: Test needs winapi!')
return false
end
print("spawn " .. file)
if not TESTING then
if cwd then lake.chdir(cwd) end
assert(winapi.shell_exec(nil, LUA_RUNNER, file, cwd))
if cwd then lake.chdir("<") end
print()
end
return true
end
local function spawn_nix(file, cwd)
print("spawn " .. file)
if not TESTING then
if cwd then lake.chdir(cwd) end
local status, code = utils.execute( LUA_RUNNER .. file .. ' &', true )
if cwd then lake.chdir("<") end
print()
return status, code
end
return true
end
spawn = WINDOWS and spawn_win or spawn_nix
end
function as_bool(v,d)
if v == nil then return not not d end
local n = tonumber(v)
if n == 0 then return false end
if n then return true end
return false
end
-----------------------
-- needs --
-----------------------
lake.define_need('lua52', function()
return {
incdir = J(ENV.LUA_DIR_5_2, 'include');
libdir = J(ENV.LUA_DIR_5_2, 'lib');
libs = {'lua52'};
}
end)
lake.define_need('lua51', function()
return {
incdir = J(ENV.LUA_DIR, 'include');
libdir = J(ENV.LUA_DIR, 'lib');
libs = {'lua5.1'};
}
end)
|