[Coverage] [-ERROR-] Found a duplicate class
Opened this issue · 4 comments
Hello,
We are using this gem to generate the cobertura report from simplecov to display on Jenkins.
However, Jenkins is complaining that it has duplicated classes when processing it. Every class with the same name on different scopes are detected as duplicated
[Coverage] [-ERROR-] Errors during parsing
[Coverage] [-ERROR-] Found a duplicate class 'query_authorisation' in 'query_authorisation.rb'
...
[Coverage] [-ERROR-] ... skipped logging of 331 additional errors ...
[Coverage] Recording coverage results
Looking at the generated file I can see the following:
$ grep query_authorisation coverage.xml
<class name="query_authorisation" filename="app/graphql/concerns/dynamic_checklists/query_authorisation.rb" line-rate="0.5" branch-rate="0.0" complexity="0">
<class name="query_authorisation" filename="app/graphql/concerns/dynamic_forms/query_authorisation.rb" line-rate="1.0" branch-rate="0.83" complexity="0">
It seems that the class is reported as the file name, not as the ruby class name with namespace. So, apart from issuing an error on parse, I suppose it's not properly reporting a full coverage report for the duplicated classes.
We are running into the same problem. Given this coverage report:
grep consultants_controller tmp/ci_reports/coverage/coverage.xml
<class name="consultants_controller" filename="app/controllers/admin/consultants_controller.rb" line-rate="0.67" complexity="0">
<class name="consultants_controller" filename="app/controllers/consultants_controller.rb" line-rate="1.0" complexity="0">
We get the following error from the Jenkins Coverage plugin:
java.lang.IllegalArgumentException: There is already a child [CLASS] consultants_controller <0>
with the name consultants_controller in [FILE] consultants_controller.rb <1, LINE: 100.00% (15/15)>
There is an open issue about a similar problem related to handling non-unique name
attributes.
It'd be great if we could set name
to the class name including the full namespace (For the above example that'd be Admin::ConsultantsController
and ConsultantsController
).
But, I think the original Simplecov report object that's passed to the formatter probably doesn't have that information and one would have to derive the namespace from the file's location, feels hacky though?!
For reference, it seems the name attribute is set here.
A cobertura report supports packages as nodes above the classes. So it might make sense to write this information as well. One could recreate that structure after parsing the coverage file but it would make much more sense to directly write the report with the correct structure.
A cobertura report supports packages as nodes above the classes. So it might make sense to write this information as well. One could recreate that structure after parsing the coverage file but it would make much more sense to directly write the report with the correct structure.
It seems it is writing the package, but not as the ruby namespaces, but as the simplecov configured groups:
simplecov-cobertura/lib/simplecov-cobertura.rb
Lines 56 to 61 in d7331c2
It should use the class namespace instead, but it seems simplecov does not provide that info?
Simplecov builds on top of the Coverage
module from the standard library, which already doesn't have that info, it seems:
https://docs.ruby-lang.org/en/master/Coverage.html