github.com/hootrhino/gopher-lua@v1.0.3/_lua5.1-tests/all.lua (about) 1 #!../lua 2 3 math.randomseed(0) 4 5 collectgarbage("setstepmul", 180) 6 collectgarbage("setpause", 190) 7 8 9 --[=[ 10 example of a long [comment], 11 [[spanning several [lines]]] 12 13 ]=] 14 15 print("current path:\n " .. string.gsub(package.path, ";", "\n ")) 16 17 18 local msgs = {} 19 function Message (m) 20 print(m) 21 msgs[#msgs+1] = string.sub(m, 3, -3) 22 end 23 24 25 local c = os.clock() 26 27 assert(os.setlocale"C") 28 29 local T,print,gcinfo,format,write,assert,type = 30 T,print,gcinfo,string.format,io.write,assert,type 31 32 local function formatmem (m) 33 if m < 1024 then return m 34 else 35 m = m/1024 - m/1024%1 36 if m < 1024 then return m.."K" 37 else 38 m = m/1024 - m/1024%1 39 return m.."M" 40 end 41 end 42 end 43 44 local showmem = function () 45 if not T then 46 print(format(" ---- total memory: %s ----\n", formatmem(gcinfo()))) 47 else 48 T.checkmemory() 49 local a,b,c = T.totalmem() 50 local d,e = gcinfo() 51 print(format( 52 "\n ---- total memory: %s (%dK), max use: %s, blocks: %d\n", 53 formatmem(a), d, formatmem(c), b)) 54 end 55 end 56 57 58 -- 59 -- redefine dofile to run files through dump/undump 60 -- 61 dofile = function (n) 62 showmem() 63 local f = assert(loadfile(n)) 64 local b = string.dump(f) 65 f = assert(loadstring(b)) 66 return f() 67 end 68 69 dofile('main.lua') 70 71 do 72 local u = newproxy(true) 73 local newproxy, stderr = newproxy, io.stderr 74 getmetatable(u).__gc = function (o) 75 stderr:write'.' 76 newproxy(o) 77 end 78 end 79 80 local f = assert(loadfile('gc.lua')) 81 f() 82 dofile('db.lua') 83 assert(dofile('calls.lua') == deep and deep) 84 dofile('strings.lua') 85 dofile('literals.lua') 86 assert(dofile('attrib.lua') == 27) 87 assert(dofile('locals.lua') == 5) 88 dofile('constructs.lua') 89 dofile('code.lua') 90 do 91 local f = coroutine.wrap(assert(loadfile('big.lua'))) 92 assert(f() == 'b') 93 assert(f() == 'a') 94 end 95 dofile('nextvar.lua') 96 dofile('pm.lua') 97 dofile('api.lua') 98 assert(dofile('events.lua') == 12) 99 dofile('vararg.lua') 100 dofile('closure.lua') 101 dofile('errors.lua') 102 dofile('math.lua') 103 dofile('sort.lua') 104 assert(dofile('verybig.lua') == 10); collectgarbage() 105 dofile('files.lua') 106 107 if #msgs > 0 then 108 print("\ntests not performed:") 109 for i=1,#msgs do 110 print(msgs[i]) 111 end 112 print() 113 end 114 115 print("final OK !!!") 116 print('cleaning all!!!!') 117 118 debug.sethook(function (a) assert(type(a) == 'string') end, "cr") 119 120 local _G, collectgarbage, showmem, print, format, clock = 121 _G, collectgarbage, showmem, print, format, os.clock 122 123 local a={} 124 for n in pairs(_G) do a[n] = 1 end 125 a.tostring = nil 126 a.___Glob = nil 127 for n in pairs(a) do _G[n] = nil end 128 129 a = nil 130 collectgarbage() 131 collectgarbage() 132 collectgarbage() 133 collectgarbage() 134 collectgarbage() 135 collectgarbage();showmem() 136 137 print(format("\n\ntotal time: %.2f\n", clock()-c))