Hi there, i've tried to setup code coverage for various nim projects and i'm having a hard time making it work consistently.
First of all, i'm using lcov on the generated binary with --debugger:native --lineDir:on and compiler specific coverage flags like --passC:-fprofile-arcs --passC:-ftest-coverage --passL:-fprofile-arcs. Everything seems to be way off, lines are completely borked in the generated report, plus i get several warnings and errors during collection, for example:
geninfo: WARNING: (range) unknown branch at line '548' in /opt/homebrew/Cellar/nim/2.2.4/nim/lib/system/orc.nim: there are only 547 lines in the file.
Use 'geninfo --filter range' to remove out-of-range lines.
(use "geninfo --ignore-errors range,range ..." to suppress this warning)
geninfo: WARNING: (range) unknown branch at line '840' in /Users/kunitoki/Projects/protogen/src/parser.nim: there are only 510 lines in the file.
geninfo: WARNING: (range) unknown line '54' in /opt/homebrew/Cellar/nim/2.2.4/nim/lib/system/cellseqs_v2.nim: there are only 53 lines in the file.
geninfo: WARNING: (range) unknown line '88' in /opt/homebrew/Cellar/nim/2.2.4/nim/lib/std/exitprocs.nim: there are only 87 lines in the file.
geninfo: WARNING: (range) unknown branch at line '398' in /Users/kunitoki/Projects/protogen/src/lexer.nim: there are only 292 lines in the file.
geninfo: WARNING: (range) unknown branch at line '394' in /opt/homebrew/Cellar/nim/2.2.4/nim/lib/system/chcks.nim: there are only 166 lines in the file.
geninfo: WARNING: (range) unknown line '195' in /Users/kunitoki/Projects/protogen/src/schema.nim: there are only 194 lines in the file.
geninfo: WARNING: (range) unknown branch at line '1694' in /opt/homebrew/Cellar/nim/2.2.4/nim/lib/pure/collections/setimpl.nim: there are only 156 lines in the file.
geninfo: WARNING: (range) unknown line '117' in /opt/homebrew/Cellar/nim/2.2.4/nim/lib/std/private/digitsutils.nim: there are only 116 lines in the file.
geninfo: WARNING: (range) unknown branch at line '1000000' in /opt/homebrew/Cellar/nim/2.2.4/nim/lib/system/iterators.nim: there are only 353 lines in the file.
geninfo: WARNING: (range) unknown branch at line '60' in /opt/homebrew/Cellar/nim/2.2.4/nim/lib/system/fatal.nim: there are only 58 lines in the file.
geninfo: WARNING: (range) unknown branch at line '2125' in /Users/kunitoki/Projects/protogen/src/cppcodegen.nim: there are only 635 lines in the file.
geninfo: WARNING: (range) unknown branch at line '395' in /opt/homebrew/Cellar/nim/2.2.4/nim/lib/std/cmdline.nim: there are only 311 lines in the file.
geninfo: WARNING: (range) unknown branch at line '864' in /opt/homebrew/Cellar/nim/2.2.4/nim/lib/pure/unittest.nim: there are only 804 lines in the file.
this generates a report that is looking suspicious, for example in a method i have these instructions:
127 [ - + ]: 14 : f.value = p.parseValue()
128 : 0 : fields.add f
129 [ + + ]: 24 : if not p.match(tkComma): break so line 127 is hit 14 times, but the line just after that is hit 0 times, followed by an instruction hit 24 times, but as you see no conditional are used (nor templates/macros) and the binary is compiled in debug so inlining shouldn't have kicked in.
I've seen there is this one (https://github.com/yglukhov/coverage) which should instrument nim instructions instead of C ones, but it's rather intrusive and in the end, i still get inconsistent results.
Does anybody have been getting this to work consistently ?