norman / telescope

A highly customizable test library for Lua that allows declarative tests with nested contexts.
http://norman.github.com/telescope/
160 stars 35 forks source link

Telescope is too sensitive to syntax errors on test files #4

Closed kikito closed 12 years ago

kikito commented 14 years ago

I've frequently found this error when writing new tests. I forgot to close a function() with its corresponding end clause, and suddenly telescope just explodes:

telescope.lua:301: Test_spec.lua:104: '<eof>' expected near 'end'

Telescope.lua:301 currently says:

local func = assert(loadfile(path))
setfenv(func, env)()

loadfile detects a syntax error on path, and this error goes 'up' until telescope crashes.

I suggest wrapping that loadfile with function() and pcall so telescope is a bit more resilient. Something similar to this:

local func = function() assert(loadfile(path)) end
setfenv(func, env)
local status, errmsg = pcall(func)
if status == false then -- indicate that there was a syntax error on the path
else -- regular treatment of path here    
norman commented 14 years ago

Yeah, this would definitely be an improvement. I've got a very busy 2 weeks coming up but will try to do this as soon as I can.