Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Coverage] [-ERROR-] Found a duplicate class #29

Open
frsantos opened this issue Apr 30, 2024 · 4 comments
Open

[Coverage] [-ERROR-] Found a duplicate class #29

frsantos opened this issue Apr 30, 2024 · 4 comments

Comments

@frsantos
Copy link

frsantos commented Apr 30, 2024

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.

@dsager
Copy link

dsager commented May 30, 2024

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.

@uhafner
Copy link

uhafner commented Jun 3, 2024

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.

@frsantos
Copy link
Author

frsantos commented Jun 3, 2024

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:

groups.each do |name, files|
next if files.empty?
packages.add_element(package = REXML::Element.new('package'))
set_package_attributes(package, name, files)
package.add_element(classes = REXML::Element.new('classes'))

It should use the class namespace instead, but it seems simplecov does not provide that info?

@dsager
Copy link

dsager commented Jun 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants