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

tsc's callbacks don't support non-rvalued expressions #3

Closed kikito closed 14 years ago

kikito commented 14 years ago

By non-rvalued expressions I mean expressions that can not be used on the right side of an assignment.

The usual example of non-rvalues on lua are assignments themselves. If you put an assignment (or any other expression without an r-value) on a callback tsc throws an error.

Example:

tsc --before="a=1" -t *.lua

The conflict can be found on this line:

http://github.com/norman/telescope/blob/master/tsc#L254

This line appends 'return ' to the callback string; return needs an r-valued expression on its right side, or else it fails.

The simplest fix is removing the 'return':

add_callback(callback, loadstring(opts[callback])())

If for some reason (i.e. tests failing) the "return" is needed, then the opts[callback] should be encased inside a (function() ... end)() call, like so:

add_callback(callback, loadstring('return (function() ' .. opts[callback] .. ' end)()' )())

This should have the same behaviour as before, but allowing assignments on callbacks.

Regards!

norman commented 14 years ago

Thanks for submitting this. I added your suggested change; I think the return was there from an earlier stage in telescope's development and was no longer needed, so I simply removed it.

kikito commented 14 years ago

Awesome! Thanks!