lunarmodules / luacov

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

Symbolic link issues on MacOS #96

Open prgp opened 2 years ago

prgp commented 2 years ago

There appears to be a minor issue when luacov attempts to scan over a symbolic link - I suspect the issue is actually in lfs which should return a mode attribute of 'link' for a symbolic link, but instead it returns nil as the attributes table which causes a nil dereference:

lua: .../Cellar/luarocks/3.8.0/share/lua/5.4/luacov/reporter.lua:133: attempt to index a nil value (local 'attr')
stack traceback:
    .../Cellar/luarocks/3.8.0/share/lua/5.4/luacov/reporter.lua:133: in local 'add_empty_dir_coverage_data'
    .../Cellar/luarocks/3.8.0/share/lua/5.4/luacov/reporter.lua:141: in method 'new'
    .../Cellar/luarocks/3.8.0/share/lua/5.4/luacov/reporter.lua:489: in function 'luacov.reporter.report'
    ...ew/Cellar/luarocks/3.8.0/share/lua/5.4/luacov/runner.lua:134: in function 'luacov.run_report'
    ...ew/Cellar/luarocks/3.8.0/share/lua/5.4/luacov/runner.lua:147: in upvalue 'on_exit'
    ...ew/Cellar/luarocks/3.8.0/share/lua/5.4/luacov/runner.lua:469: in function 'luaunit.oldOsExit'
    ...homebrew/Cellar/luarocks/3.8.0/share/lua/5.4/luaunit.lua:132: in function 'os.exit'
    test/test_suite.lua:16: in main chunk
    [C]: in ?

I have a work-around which guards against this issue, but does not fix the underlying problem.

Build System Used

MacOS: 11.6.7 (M1)
Lua: 5.4
luarocks versions:
    luacov: 0.15.0-1
    luafilesystem: 1.8.0-1

Work-around patch to reporter.lua

Adding an extra guard attr and seems to "fix" the issue.

line 36:

if attr and attr.mode == "directory" then

line 133

if attr and attr.mode == "file" and fileMatches(filename, '.%.lua$') then
hishamhm commented 1 year ago

Hi! Could you send a PR with the workaround? Thanks!