lua-users home
lua-l archive

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

  [*]: Ahh, new idea: Unit testing using examples in the docstring ...

You're probably being sarcastic since you are using the term "docstring", but if not, you might get some ideas from python's doctest module [1], which is rather mature.


On Thu, Apr 25, 2013 at 8:43 AM, Philipp Janda <> wrote:
Am 25.04.2013 08:29 schröbte Geoff Leyland:
Hi Phillip,


On 25/04/2013, at 10:02 AM, Philipp Janda <> wrote:

Hello fellow Lua users!

Do you like Python's docstrings or their Lua equivalent[1]?
Do you want your Lua function definitions to look like this ...
... to get type checking for function arguments and/or return values?


[1] does a similar argument-checking thing.  It parses special LDoc comments (that LDoc now supports) and uses a hook, rather than a decorator (hooks are unfortunately very slow, but at least optional).

I think those tools have more chances of being successful if they reuse information that is already there or at least has other benefits besides type checking. It increases the motivation to actually write annotations, and maybe you can even detect outdated documentation during unit testing[*]. So reusing LDoc comments is a good idea, IMHO.

 Comment syntax is inspired by [2], which is also an argument checker, and there was a conversation about argument checking last year [3]

There is also this wiki page[4], and some time ago I implemented the typecheck decorator outlined here[5]. But what upset me was that none of my attempts at type checking could even handle the Lua standard library (especially table.insert( table, [pos,] value ) was #$!%..., and return values are not that easy either (e.g. somevalue _or_ nil,errormessage)). Btw., that's also the reason why I'm not entirely convinced that Luadoc's/LDoc's current comment format is the best fit for Lua.

I already knew about checks[2], and I like it because it requires little code, and probably is faster than most other attempts (although I would have merged the checks function and the checkers table into one functable[6] and returned it via require without setting a global). The custom type functions for checks and annotate should be compatible.



Philipp   [*]: Ahh, new idea: Unit testing using examples in the docstring ...