livefront / danger-shroud

🧛🏼‍♂️A danger plugin for enforcing code coverage via a Jacoco coverage report 🧛🏼‍♂️
https://livefront.com/shroud/
Apache License 2.0
12 stars 5 forks source link

Jacoco: File name collisions break coverage calculation #35

Open collin-livefront opened 1 year ago

collin-livefront commented 1 year ago

Any two files with identical names will make Danger/Shroud output bogus numbers for the coverage percentage.

It's not too strange on a large project (perhaps with many modules) to have a couple files in different packages, but the same name. Eg,

com.my.app.feature_one.DomainExtensions
com.my.app.feature_two.DomainExtensions

When Shroud parses the jacoco report xml, it only looks at the file name, not the fully qualified path. https://github.com/livefront/danger-shroud/blob/54fe4c62d182be18250c3b6ff73a9afb6ac5b84a/lib/shroud/plugin.rb#L147

The sourcefilename field in xml is used to add together all the covered/missed lines, but if there happen to be two (or more) files with that name, Shroud will pull all line coverage from each file, leading to a larger denominator than expected.

Instead, Shroud should use the fully qualified class name as the key, which would keep each file as a distinct record when aggregating coverage counts.

collin-livefront commented 1 year ago

I ran into this on a large multi-module project, where a team was orchestrating a code migration across modules and had some temporarily duplicated file names (though with different packages).