lunarmodules / luacov

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

Html reporter not working #98

Closed dwenegar closed 1 year ago

dwenegar commented 2 years ago

The files and modules required by the html reporter are not installed.

mrpudn commented 2 years ago

The reason is that the HTML reporter was added recently in #93 and a new version has not yet been released to LuaRocks. The version that I'm using (0.15.0) is the latest version in LuaRocks and was released about a year ago.

/usr/local/opt/lua/bin/lua5.4: /usr/local/share/lua/5.4/luacov/runner.lua:134: module 'luacov.reporter.html' not found:
    No LuaRocks module found for luacov.reporter.html
    no field package.preload['luacov.reporter.html']
    no file '.../.luarocks/share/lua/5.4/luacov/reporter/html.lua'
    no file '.../.luarocks/share/lua/5.4/luacov/reporter/html/init.lua'
    no file '/usr/local/share/lua/5.4/luacov/reporter/html.lua'
    no file '/usr/local/share/lua/5.4/luacov/reporter/html/init.lua'
    no file '/usr/local/lib/lua/5.4/luacov/reporter/html.lua'
    no file '/usr/local/lib/lua/5.4/luacov/reporter/html/init.lua'
    no file './luacov/reporter/html.lua'
    no file './luacov/reporter/html/init.lua'
    no file '.../.luarocks/lib/lua/5.4/luacov/reporter/html.so'
    no file '/usr/local/lib/lua/5.4/luacov/reporter/html.so'
    no file '/usr/local/lib/lua/5.4/loadall.so'
    no file './luacov/reporter/html.so'
    no file '.../.luarocks/lib/lua/5.4/luacov.so'
    no file '/usr/local/lib/lua/5.4/luacov.so'
    no file '/usr/local/lib/lua/5.4/loadall.so'
    no file './luacov.so'
stack traceback:
    [C]: in function 'require'
    /usr/local/share/lua/5.4/luacov/runner.lua:134: in function 'luacov.runner.run_report'
    .../local/lib/luarocks/rocks-5.4/luacov/0.15.0-1/bin/luacov:99: in main chunk
    [C]: in ?
↪ lua -v
Lua 5.4.4  Copyright (C) 1994-2022 Lua.org, PUC-Rio

↪ luacov -h
LuaCov 0.15.0 - coverage analyzer for Lua scripts

Looks like this project is being transitioned to a new org, so the team is likely working on updating the release process. In order to use the latest version in the meantime, you will probably need to install the project manually.

This might also be an option for generating HTML reports for now: https://github.com/to-kr/luacov-multiple

Aire-One commented 1 year ago

Hello,

I investigated for a bit on this issue. The rockspec file need to be updated to include the HTML reporter module. In addition, the static files from src/luacov/reporter/html must be copied to the installation directory. This second step is harder to achieve.

The best I could do was to copy the directory with build.copy_directories in the rockspec. But it requires changing the line https://github.com/lunarmodules/luacov/blob/c915f4b95e8df5dbfaf2b1f04f0b7da04506fc7a/src/luacov/reporter/html.lua#L17

In my case, after installing the module from Luarocks, it tries to read from /usr/share/lua/5.4/luacov/reporter/html while Luarocks build.copy_directories copies the files to /usr/lib/luarocks/rocks-5.4/luacov/scm-1/src/luacov/reporter/html

Here is a quick path I have to allow the HTML reporter to work. It's no idea to have the directory hard codded like this...

diff --git a/luacov-scm-1.rockspec b/luacov-scm-1.rockspec
index 4df09b3..1c9564a 100644
--- a/luacov-scm-1.rockspec
+++ b/luacov-scm-1.rockspec
@@ -28,6 +28,8 @@ build = {
       ["luacov.linescanner"] = "src/luacov/linescanner.lua",
       ["luacov.reporter"] = "src/luacov/reporter.lua",
       ["luacov.reporter.default"] = "src/luacov/reporter/default.lua",
+      ["luacov.reporter.html"] = "src/luacov/reporter/html.lua",
+      ["luacov.reporter.html.template"] = "src/luacov/reporter/html/template.lua",
       ["luacov.runner"] = "src/luacov/runner.lua",
       ["luacov.stats"] = "src/luacov/stats.lua",
       ["luacov.tick"] = "src/luacov/tick.lua",
@@ -36,6 +38,9 @@ build = {
    install = {
       bin = {
          luacov = "src/bin/luacov"
-      }
-   }
+      },
+   },
+   copy_directories = {
+      "src/luacov/reporter/html",
+   },
 }
diff --git a/src/luacov/reporter/html.lua b/src/luacov/reporter/html.lua
index e0fb080..c0c667b 100644
--- a/src/luacov/reporter/html.lua
+++ b/src/luacov/reporter/html.lua
@@ -14,7 +14,8 @@ end
 ----------------------------------------------------------------
 --- parse template
 do
-    local dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1")
+    -- local dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1")
+    local dir = "/usr/lib/luarocks/rocks-5.4/luacov/scm-1/src/luacov/reporter/"
     local dir_sep = package.config:sub(1, 1)
     if not dir_sep:find("[/\\]") then
         dir_sep = "/"