dashingrocket / simplecov-cobertura Goto Github PK
View Code? Open in Web Editor NEWRuby SimpleCov Cobertura Formatter
License: Apache License 2.0
Ruby SimpleCov Cobertura Formatter
License: Apache License 2.0
Hello, I'm trying to run the test suite, but I run into 1 test error.
ruby 3.0.6
nokogiri 1.13.9
Output when running rake:
Loaded suite /usr/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/rake_test_loader
Started
Coverage report generated for Unit Tests to /home/micwoj92/Documents/pkg/fog/simplecov-cobertura/tmp/coverage.xml. 6 / 7 LOC (85.71%) covered; 3 / 6 BC (50.00%) covered
E
==============================================================================================================================================================================================================================================
Error: test_format_dtd_validates(CoberturaFormatterTest): NoMethodError: undefined method `validate' for nil:NilClass
/home/micwoj92/Documents/pkg/fog/simplecov-cobertura/test/simplecov-cobertura_test.rb:56:in `test_format_dtd_validates'
53: xml = @formatter.format(@result)
54: options = Nokogiri::XML::ParseOptions::DTDLOAD
55: doc = Nokogiri::XML::Document.parse(xml, nil, nil, options)
=> 56: assert_empty doc.external_subset.validate(doc)
57: end
58:
59: def test_no_groups
==============================================================================================================================================================================================================================================
Coverage report generated for Unit Tests to /home/micwoj92/Documents/pkg/fog/simplecov-cobertura/tmp/cobertura.xml. 6 / 7 LOC (85.71%) covered; 3 / 6 BC (50.00%) covered
|Coverage report generated for Unit Tests to /home/micwoj92/Documents/pkg/fog/simplecov-cobertura/tmp/coverage.xml. 6 / 7 LOC (85.71%) covered; 3 / 6 BC (50.00%) covered
/Coverage report generated for Unit Tests to /home/micwoj92/Documents/pkg/fog/simplecov-cobertura/tmp/coverage.xml. 6 / 7 LOC (85.71%) covered; 3 / 6 BC (50.00%) covered
-Coverage report generated for Unit Tests to /home/micwoj92/Documents/pkg/fog/simplecov-cobertura/tmp/coverage.xml. 6 / 7 LOC (85.71%) covered; 3 / 6 BC (50.00%) covered
\Coverage report generated for Unit Tests to /tmp/tmp/coverage.xml. 6 / 7 LOC (85.71%) covered; 3 / 6 BC (50.00%) covered
Finished in 0.137903972 seconds.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7 tests, 66 assertions, 0 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
85.7143% passed
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
50.76 tests/s, 478.59 assertions/s
rake aborted!
Command failed with status (1)
Tasks: TOP => default => test
(See full trace by running task with --trace)
Assuming SimpleCov.root
is /
, which could happen in some forms of container builds, then the generated filename
attributes are cut off incorrectly.
Example:
Full path | Expected result | Actual result |
---|---|---|
/foo/bar.rb |
foo/bar.rb |
oo/bar.rb |
This happens because the code that tries to strip away the project root assumes that it must be at least 1 character before the path separator, which is not true with a path like "/"
.
filename = file.filename
# Here is the problem; the +1 assumes that SimpleCov.root.length is just before
# the path separator, while for the case of "/" it is actually *on* the path
# separator.
path = filename[SimpleCov.root.length+1..-1]
class_.attributes['name'] = File.basename(filename, '.*')
class_.attributes['filename'] = path
The real reason I get this
I'm trying to set up code coverage reporting on GitLab, which does not support the <source>
element and instead requires the filename
to be the full path to the file from the repo root.
However, this repo contains several projects and so the actual project root is not at the repo root. This would not have been a problem, as I could just adjust the SimpleCov.root
, but the tests run inside a container where the app is just one directory below the root (/myapp
). So I have to set the root
to /
to get it to include the myapp/
part in the filename
so Gitlab can resolve the file from <repo root>/myapp/foo/bar.rb
.
You could say this is a perfect storm of edge cases, and I would agree.
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.
I see no support for branch coverage in the readme. But I would like to start the process of implementation of that one somehow.
according to cobertura documentation - branch coverage is supported.
https://www.baeldung.com/cobertura#2-configuring-code-coverage-calculation-and-checks
simplecov supports branch coverage as well
https://github.com/simplecov-ruby/simplecov#branch-coverage-ruby--25
let's implement that one finally :)
The timestamp generated in report header seems wrong
<?xml version='1.0'?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<!-- Generated by simplecov-cobertura version 1.3.1 (https://github.com/dashingrocket/simplecov-cobertura) -->
<coverage line-rate="1.0" branch-rate="0" lines-covered="226" lines-valid="226" branches-covered="0" branches-valid="0" complexity="0" version="0" timestamp="1476766800">
Gitlab recommends using simplecov-cobertura in their documentation. Elsewhere, they have recommended coverage regex parsing for badge creation, but simplecov-cobertura doesn't output what they're looking for. The HTML formatter does, though
HTML Output:
Coverage report generated for Unit Tests to /project/path/coverage. 67 / 67 LOC (100.0%) covered.
Cobertura Output:
Coverage report generated for Unit Tests to /Users/jbowes/temp/pagecheck/coverage/coverage.xml
Investigate adding the coverage to stdout for simplecov-cobertura
Full warning:
Deprecation Warnings:
The SimpleCov::Formatter::CoberturaFormatter formatter uses the deprecated formatter interface not supported directly by RSpec 3. To continue to use this formatter you must install the `rspec-legacy_formatters` gem, which provides support for legacy formatters or upgrade the formatter to a compatible version. Formatter added at: /Users/my-user/.rvm/gems/ruby-2.5.1@app/gems/rspec-core-3.7.1/exe/rspec:4:in `<top (required)>'
If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
1 deprecation warning total
Reproduction steps:
bundle exec rspec --format SimpleCov::Formatter::CoberturaFormatter
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.