User:Jeblad/Coverage in Lua

From mediawiki.org

It is several ways to measure w:code coverage at the different levels in a piece of code. There are coverage at function, statement, branch, and condition levels. In Lua it is pretty easy to attach an alternate function that captures calls and reports them, thereby giving a coverage measure at function level. An alternative could be to inject function calls in the code, but as each statement lacks an easy detectable separator it is slightly difficult to insert functions at safe places. It is not safe to just inject the function call at the beginning on each line.

If there is a pretty simple parser that steps through the code, skipping parts that can't be properly parsed (comments and text), and then injects function calls on important code fragments, then branch or condition coverage can be measured. This should be pretty safe.

The following is the trick to fake lookbehing by using lookahead in Javascript. It is handy for detecting escaped characters.

/(?:(["'])(?:(?!\\['"])[^"'])*\1)/

Examples[edit]