naming & refactoring

This commit is contained in:
kikito 2013-09-03 13:20:38 +02:00
parent 3a90dc3319
commit c1e5b44938
2 changed files with 13 additions and 7 deletions

View File

@ -65,14 +65,14 @@ local function run(f, options)
-- I would love to be able to make step greater than 1 -- I would love to be able to make step greater than 1
-- (say, 500000) but any value > 1 seems to choke with a simple while true do end -- (say, 500000) but any value > 1 seems to choke with a simple while true do end
-- After ~100 iterations, they stop calling timeout. So I need to use step = 1 and -- After ~100 iterations, they stop calling timeout. So I need to use step = 1 and
-- count the steps separatedly -- instructions_count the steps separatedly
local step = 1 local step = 1
local count = 0 local instructions_count = 0
local timeout = function(str) local timeout = function(str)
count = count + 1 instructions_count = instructions_count + 1
if count >= limit then if instructions_count >= limit then
cleanup() cleanup()
error('Timeout') error('Quota exceeded: ' .. tostring(instructions_count) .. '/' .. tostring(limit) .. ' instructions')
end end
end end
debug.sethook(timeout, "", step) debug.sethook(timeout, "", step)

View File

@ -40,13 +40,19 @@ describe('sandbox', function()
describe('when handling infinite loops', function() describe('when handling infinite loops', function()
it('throws an error with infinite loops', function() it('throws an error with infinite loops', function()
assert.has_error(function() sandbox("while true do end") end) assert.has_error(function() sandbox("while true do end") end)
end) end)
it('restores string.rep even after a while true', function()
assert.has_error(function() sandbox("while true do end") end)
assert.equal('hellohello', string.rep('hello', 2))
end)
it('#focus accepts a limit param', function() it('#focus accepts a limit param', function()
--assert.no_has_error(function() sandbox("for i=1,10000 do end") end) assert.no_has_error(function() sandbox("for i=1,100 do end") end)
assert.has_error(function() sandbox("for i=1,10000 do end", {limit = 50}) end) assert.has_error(function() sandbox("for i=1,100 do end", {limit = 50}) end)
end) end)
end) end)