-
Notifications
You must be signed in to change notification settings - Fork 668
/
Copy pathall.lua
137 lines (111 loc) · 2.65 KB
/
all.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!../lua
math.randomseed(0)
collectgarbage("setstepmul", 180)
collectgarbage("setpause", 190)
--[=[
example of a long [comment],
[[spanning several [lines]]]
]=]
print("current path:\n " .. string.gsub(package.path, ";", "\n "))
local msgs = {}
function Message (m)
print(m)
msgs[#msgs+1] = string.sub(m, 3, -3)
end
local c = os.clock()
assert(os.setlocale"C")
local T,print,gcinfo,format,write,assert,type =
T,print,gcinfo,string.format,io.write,assert,type
local function formatmem (m)
if m < 1024 then return m
else
m = m/1024 - m/1024%1
if m < 1024 then return m.."K"
else
m = m/1024 - m/1024%1
return m.."M"
end
end
end
local showmem = function ()
if not T then
print(format(" ---- total memory: %s ----\n", formatmem(gcinfo())))
else
T.checkmemory()
local a,b,c = T.totalmem()
local d,e = gcinfo()
print(format(
"\n ---- total memory: %s (%dK), max use: %s, blocks: %d\n",
formatmem(a), d, formatmem(c), b))
end
end
--
-- redefine dofile to run files through dump/undump
--
dofile = function (n)
showmem()
local f = assert(loadfile(n))
local b = string.dump(f)
f = assert(loadstring(b))
return f()
end
dofile('main.lua')
do
local u = newproxy(true)
local newproxy, stderr = newproxy, io.stderr
getmetatable(u).__gc = function (o)
stderr:write'.'
newproxy(o)
end
end
local f = assert(loadfile('gc.lua'))
f()
dofile('db.lua')
assert(dofile('calls.lua') == deep and deep)
dofile('strings.lua')
dofile('literals.lua')
assert(dofile('attrib.lua') == 27)
assert(dofile('locals.lua') == 5)
dofile('constructs.lua')
dofile('code.lua')
do
local f = coroutine.wrap(assert(loadfile('big.lua')))
assert(f() == 'b')
assert(f() == 'a')
end
dofile('nextvar.lua')
dofile('pm.lua')
dofile('api.lua')
assert(dofile('events.lua') == 12)
dofile('vararg.lua')
dofile('closure.lua')
dofile('errors.lua')
dofile('math.lua')
dofile('sort.lua')
assert(dofile('verybig.lua') == 10); collectgarbage()
dofile('files.lua')
if #msgs > 0 then
print("\ntests not performed:")
for i=1,#msgs do
print(msgs[i])
end
print()
end
print("final OK !!!")
print('cleaning all!!!!')
debug.sethook(function (a) assert(type(a) == 'string') end, "cr")
local _G, collectgarbage, showmem, print, format, clock =
_G, collectgarbage, showmem, print, format, os.clock
local a={}
for n in pairs(_G) do a[n] = 1 end
a.tostring = nil
a.___Glob = nil
for n in pairs(a) do _G[n] = nil end
a = nil
collectgarbage()
collectgarbage()
collectgarbage()
collectgarbage()
collectgarbage()
collectgarbage();showmem()
print(format("\n\ntotal time: %.2f\n", clock()-c))