luacov icon indicating copy to clipboard operation
luacov copied to clipboard

LuaCov marks certain lines as uncovered when they are clearly covered

Open philhassey opened this issue 11 years ago • 7 comments

Here is some Lua code with examples:

function test1()
    local thing = nil -- MISSED BY LUACOV
    print("test1")
end
test1()

function test2()
    local stuff = function (x) return x end
    local thing = stuff({
        b = { name = 'bob',
        },
        -- comment
    }) -- MISSED BY LUACOV
    print("test2")
end
test2()

function test3()
    if true then -- MISSED BY LUACOV
        print("test3")
    end
end
test3()

function test4()
    while true do -- MISSED BY LUACOV
        print("test4")
        break
    end
end
test4()

philhassey avatar Feb 08 '14 18:02 philhassey

Thank you for the test case! Fixed in the current upstream repository of luacov at keplerproject/luacov

hishamhm avatar Feb 08 '14 22:02 hishamhm

Great, thanks a ton for fixing this.

philhassey avatar Feb 08 '14 22:02 philhassey

test2, test3, test4 appear to be fixed - thanks!

test1 is still being missed.

I've got Lua 5.1.5 on OS X Mavericks if that makes any difference.

philhassey avatar Feb 08 '14 23:02 philhassey

That works differently in Lua 5.1 and 5.2... it's a bit harder to fix without risking to add exclusions that overreach.

hishamhm avatar Feb 08 '14 23:02 hishamhm

Good to know, thanks for checking. Could there be a comment keyword like "--LUACOV:IGNORE" that could be added for quirks or the occasional line of code that I don't want marked?

philhassey avatar Feb 08 '14 23:02 philhassey

Here's another example:

function test5()
    if true then if true then -- MISSED BY LUACOV
        print("test5")
    end end -- MISSED BY LUACOV
end
test5()

philhassey avatar Feb 11 '14 21:02 philhassey

Thanks for the feedback. LuaCov won't detect constructs like this as long as we're doing a simple line-per-line scan and not a full-fledged syntax tree analysis. It's easy to create synthetic examples like this that make it break. I think the simplicity of a no-dependencies module is worth the lack of robustness in those corner cases.

hishamhm avatar Feb 11 '14 21:02 hishamhm