lunarmodules / luacov

LuaCov is a simple coverage analyzer for Lua code.
http://lunarmodules.github.io/luacov/
MIT License
294 stars 66 forks source link

Last entry in multi-line table definition missed if there's no trailing comma #52

Open argos83 opened 7 years ago

argos83 commented 7 years ago

Hi!

When defining a table in multiple lines, LuaCov misses coverage on the last entry unless it has a trailing comma.

E.g. Without trailing comma:

   11 local dummy_table = {
        ['a'] = 'A',
        ['b'] = 'B',
****0   ['c'] = 'C'
      }

With trailing comma:

   11 local dummy_table = {
        ['a'] = 'A',
        ['b'] = 'B',
        ['c'] = 'C',
      }

Thanks for this great library!

mpeterv commented 7 years ago

Hi @argos83! This problem in general is relatively difficult to detect: it's specific to LuaJIT IIRC, and simply filtering out misses on such lines is sometimes wrong because fieldname = "value" is valid outside tables and shouldn't be filtered out.

Does the problem go away when running luacov with cluacov installed?

argos83 commented 7 years ago

Hey @mpeterv, I've just tried with cluacov and the same issue occurs.

mpeterv commented 7 years ago

That's strange. cluacov fixed it for me. What version of Lua/LuaJIT are you using? I see that the first line of your example is executed 11 times so it must be a part of a larger snippet, does the issue occur when running just the example?

argos83 commented 7 years ago

Hey @mpeterv. It also happens when running just the example:

   1 local sometable = {
         ['a'] = 'A',
         ['b'] = 'B',
***0     ['c'] = 'C'
     }

I'm running lua in the context of OpenResty (v 1.11.2.2) compiled with --with-luajit which I think installs LuaJIT 2.1

hsandt commented 3 years ago

Erm... I had the exact opposite issue, where the last line would be considered uncovered only if adding a trailing comma

t = {
  1   a.b,
  1   a.c,
  1   a.d,
**0   a.e,
  1 }

I guess I shouldn't open a new issue and add my case here instead?

Did somebody send a PR trying to fix this issue, resulting in the opposite issue?