aconrad / pycobertura

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

Error when using --ignore-regex with diff #190

Open RamonMeffert opened 3 months ago

RamonMeffert commented 3 months ago

Hi! Thanks for making this tool, this seems really useful 😄

I've been playing around with the CLI a bit, and I've basically figured out how to use it. However, it seems like there is a difference between the show and diff commands when using the --ignore-regex option. The show command nicely ignores files matching the regex I give it. However, the diff command throws an error for some regexes:

$ pycobertura diff ./coverage-1.xml ./coverage-2.xml --ignore-regex ".*Tests"
Traceback (most recent call last):
  File "/home/ramon/.local/bin/pycobertura", line 8, in <module>
    sys.exit(pycobertura())
  File "/home/ramon/.local/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/ramon/.local/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/ramon/.local/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ramon/.local/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ramon/.local/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/ramon/.local/lib/python3.10/site-packages/pycobertura/cli.py", line 326, in diff
    report = reporter.generate()
  File "/home/ramon/.local/lib/python3.10/site-packages/pycobertura/reporters.py", line 362, in generate
    lines = self.get_report_lines()
  File "/home/ramon/.local/lib/python3.10/site-packages/pycobertura/reporters.py", line 242, in get_report_lines
    indexes_of_files_with_changes = [
  File "/home/ramon/.local/lib/python3.10/site-packages/pycobertura/reporters.py", line 247, in <listcomp>
    diff_total_stmts[i],
IndexError: list index out of range

The problem seems to be the .* at the beginning. When I try a different regex (e.g. simply "Tests"), I get no error but nothing is ignored either.

I've tested it on Windows 11 and on Ubuntu 22.04.3 (under WSL), the same error occurs.