How to generate Lua coverage report for built in module? - tsafin/tarantool GitHub Wiki
Assumption
Assumption is that you are running normal out-of-tree build, and current
directory is used build/
directory, not from inside of repository tree root.
If you got used to using in-source tree - please update links below accordingly.
SYNOPSIS
./src/tarantool -lluacov ../test/app-tap/datetime.test.lua
luacov builtin/datetime.lua
tail -10 luacov.report.out
Detailed approach
As a first, preparation step you need to install luacov
somewhere, where
tarantool
will be able to find it. The simplest approach would be to use
tarantoolctl rocks install luacov
which would install luacov
to the
local .rocks
directory, where Tarantool would automatically find it.
13:53 $ tarantoolctl rocks list
Installed rocks:
----------------
argparse
0.6.0-1 (installed) - /home/tsafin/datetime/tarantoolt/build/.rocks/share/tarantool/rocks
luacov
0.13.0-1 (installed) - /home/tsafin/datetime/tarantoolt/build/.rocks/share/tarantool/rocks
luafilesystem
1.7.0-2 (installed) - /home/tsafin/datetime/tarantoolt/build/.rocks/share/tarantool/rocks
Then you need to run your test with luacov
module activated (see -lluacov
in the command-line):
13:57 $ ./src/tarantool -lluacov ../test/app-tap/datetime.test.lua | head -10
TAP version 13
1..11
# Default date creation
1..9
ok - T.epoch ==0
ok - T.nsec == 0
ok - T.tzoffset == 0
ok - tostring(T1)
ok - T.epoch ==0
ok - T.nsec == 0
This invocation creates luacov.stat.out of a strange format:
15:39 $ grep -A1 datetime.lua luacov.stats.out
619:builtin/datetime.lua
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
118 0 0 0 232 0 0 0 116 0 0 48 0 0 48 0 0 81 0 0 0 81 0 0 0 0 0 164 140 0 0 24
30 15 0 18 9 0 0 0 0 2 2 2 0 2 0 0 0 0 63 0 0 0 0 120 0 0 0 7 0 0 0 0 0 0 0 189
0 0 0 13 0 0 0 13 0 0 0 3 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 9 9 6 0 3 0 0 0 36 36 36 36 36 36 0 0 0 33 33
0 0 0 17 8 9 9 0 0 0 0 234 0 0 0 0 53 3 0 50 0 0 0 50 50 50 0 50 50 26 26 0 50
50 25 25 0 50 50 27 24 0 47 47 17 17 0 47 47 16 16 0 47 47 15 15 0 0 47 141 94
47 4 0 43 2 41 2 0 43 43 14 3 0 11 3 0 8 8 0 0 8 2 6 6 3 0 5 0 0 34 34 8 4 0 0
...
You might recognize, that instead of path to the module file, we see builtin/datetime.lua
and if luacov reporter would use this path for report annotation, it would not find file, and would fail to report anything.
~/tarantool/build>
15:39 $ luacov builtin/datetime.lua
Couldn't open builtin/datetime.lua: No such file or directory
We could solve it 2 ways:
- update paths in
luacov.stats.out
to use relative path to original filename, i.e. instead ofbuiltin/datetime.lua
to point to../src/lua/datetime.lua
; - or simply create symbolic link in the directory
builtin
which would redirect to that file via relative path.
-
1st approach is sort of fragile - you would need to update
luacov.stats.out
after each luacov stats update. -
2nd approach is more convenient, IMHO, unless you intentionally cleaned up current directory, and removed
builtin/
subdirectory, this created symbolic link will continue work. Thus I recommend to use it:
15:41 $ ls -al ../src/lua/datetime.lua
-rw-r--r-- 1 tsafin tsafin 16968 Sep 28 13:56 ../src/lua/datetime.lua
~/tarantool/build>
15:42 $ mkdir builtin
~/tarantool/build>
15:45 $ cd builtin/
~/tarantool/build/builtin>
15:45 $ ln -s ../../src/lua/datetime.lua datetime.lua
~/tarantool/build/builtin>
15:45 $ cd -
/home/tsafin/datetime/tarantoolt/build
~/tarantool/build>
15:45 $ luacov builtin/datetime.lua
NB! If you do not have
luacov
installed globally, then it's available under local'.rocks
directory, and you could run it this way./src/tarantool .rocks/share/tarantool/rocks/luacov/0.13.0-1/bin/luacov builtin/datetime.lua
After these steps luacov
report is generated in the current directory
under name luacov.report.out
15:46 $ tail -10 luacov.report.out
==============================================================================
Summary
==============================================================================
File Hits Missed Coverage
-----------------------------------------
builtin/datetime.lua 245 39 86.27%
-----------------------------------------
Total 245 39 86.27%