lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello Andre,

Shake is a simple test engine for Lua that assumes that tests only use
standard assert() and print() calls:
http://shake.luaforge.net/

Thank you - I've been trying it out and ran into a small problem - which can be fixed easily.

When you replace _G.print with your own code, the replacement does not quite do what print does. I got the following error message:

/usr/local/share/lua/5.1/shake.lua:169: bad argument #1 to 'concat' (table contains non-strings)

My tables may contain userdata. The reason print works, is that it does a "tostring" (and I have made sure all my userdata metatables have a useful __tostring method).

So what I did was replace this line:

  context.output[#context.output + 1] = table.concat({...})

by:

  local o={}
  for i=1,_G.select('#',...) do
    table.insert(o,_G.tostring(_G.select(i,...)))
  end
  context.output[#context.output + 1] = table.concat(o)

And then shake works.

This is not very efficient, considering that most output never gets used/printed when run with shake. You could also append "{...}" as is to context.output[], i.e. leave it a table. Then, when actually printing convert it to the string as above. I haven't looked at the code to see where that would have to be changed.

Last comment: shouldn't it be 'table.concat({...},"\t")' ? The standard print function inserts tabs between its arguments.

Anyway, I hope this helps. Fell free to adapt, redo, ignore, throw away, whatever ;)

-jcw