-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.lua
70 lines (56 loc) · 1.66 KB
/
test.lua
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
-- Copyright (c) 2018, xiedacon.
local cjson = require "cjson"
_G.Array = require "utility.array"
_G.Object = require "utility.object"
_G.String = require "utility.string"
_G.Function = require "utility.function"
_G.utility = require "utility"
_G.test = function(v1, v2, skip)
if type(v1) == "table" then v1 = cjson.encode(v1) end
if type(v2) == "table" then v2 = cjson.encode(v2) end
local ok = skip or pcall(assert, tostring(v1) == tostring(v2))
if not ok then
print("Assert failed: \n"
.. " expect: " .. tostring(v2) .. "\n"
.. " accept: " .. tostring(v1) .. "\n")
end
end
local function popen(command, n)
if not n then n = 3 end
local result, err
for i = 1, n do
local file = io.popen(command)
result, err = file:read("*a")
file:close()
if err and err == "Interrupted system call" then
else
break
end
end
return result, err
end
local index = #popen([[pwd]], 100) + 6
local files = popen([[find $PWD/test | sort | grep \\.lua]], 100)
local current = 1
while(current <= #files) do
local from, to = string.find(files, "\n", current, true)
if to == nil then
from = #files
to = #files
end
local file = string.sub(files, current, from - 1)
local name = string.sub(file, index, #file - 4)
print("Test: " .. name)
local ok, fn = pcall(loadfile, file)
if ok then
ok, err = pcall(fn)
if not ok then
print("Failed to execute " .. name)
print(err)
end
else
print("Failed to load " .. name)
print(fn)
end
current = to + 1
end