all.lua 2.6 KB

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