aconrad / pycobertura

A code coverage diff tool for Cobertura reports
MIT License
116 stars 39 forks source link

Exception generated with `-f json` and `-f yaml` #170

Open ligurio opened 1 year ago

ligurio commented 1 year ago

Everything is ok with -f text:

$ pycobertura diff --format text -s1 . -s2 . build1/coverage/luajit.xml build8/coverage/luajit.xml 
Filename             Stmts    Miss  Cover    Missing
-----------------  -------  ------  -------  ---------
src/lj_crecord.c         0      -9  +0.78%
src/lj_gc.c              0      -1  +0.20%
src/lj_opt_fold.c        0      -8  +0.73%
src/lj_opt_mem.c         0      -9  +1.63%
src/lj_record.c          0      -2  +0.14%
src/lj_str.c             0      -7  +4.29%
TOTAL                    0     -36  +0.15%

but failed, with -f json and -f yaml:

$ pycobertura diff --format yaml -s1 . -s2 . build1/coverage/luajit.xml build8/coverage/luajit.xml 
Traceback (most recent call last):
  File "/home/sergeyb/.local/bin/pycobertura", line 8, in <module>
    sys.exit(pycobertura())
  File "/home/sergeyb/.local/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/sergeyb/.local/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/sergeyb/.local/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/sergeyb/.local/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/sergeyb/.local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/sergeyb/.local/lib/python3.10/site-packages/pycobertura/cli.py", line 326, in diff
    report = reporter.generate()
  File "/home/sergeyb/.local/lib/python3.10/site-packages/pycobertura/reporters.py", line 399, in generate
    stats_dict = self.per_file_stats(lines)
  File "/home/sergeyb/.local/lib/python3.10/site-packages/pycobertura/reporters.py", line 291, in per_file_stats
    file_stats_list = [
  File "/home/sergeyb/.local/lib/python3.10/site-packages/pycobertura/reporters.py", line 292, in <listcomp>
    {
  File "/home/sergeyb/.local/lib/python3.10/site-packages/pycobertura/reporters.py", line 293, in <dictcomp>
    header_name: header_value[file_index]
IndexError: list index out of range

Version: 3.2.1, installed via pip.