Giter Club home page Giter Club logo

simplecov-cobertura's Introduction

simplecov-cobertura

Build Gem Version Downloads

Produces Cobertura formatted XML from SimpleCov.

Output can be consumed by the Jenkins Cobertura Plugin for easy coverage visualization.

Installation

Add this line to your application's Gemfile:

gem 'simplecov-cobertura'

And then execute:

$ bundle

Or install it yourself as:

$ gem install simplecov-cobertura

Usage

require 'simplecov-cobertura'

SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter

Continuous Integration

Tested in a CI environment against the following Ruby versions:

  • 3.0
  • 2.7
  • 2.6
  • 2.5

Contributing

  1. Fork it ( https://github.com/dashingrocket/simplecov-cobertura/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

Copyright 2021 Dashing Rocket, Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

simplecov-cobertura's People

Contributors

ivailop avatar jeremiemv avatar jessebs avatar mange avatar okuramasafumi avatar rlester avatar skcc321 avatar splattael avatar st0012 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

simplecov-cobertura's Issues

Fix Deprecation Warning: The SimpleCov::Formatter::CoberturaFormatter formatter uses the deprecated formatter interface not supported directly by RSpec 3

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:

  1. Everything in the README
  2. Rspec v3 or greater
  3. Run bundle exec rspec --format SimpleCov::Formatter::CoberturaFormatter

timestamp generated in the report header is old

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">

Screen Shot 2020-07-14 at 09 57 38

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

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.

Output coverage in terminal

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

1 error in tests

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)

Generated filename attribute is invalid when project root is machine root

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.