Browse Source

We write ourselves... gem is outdated.

develop
Christian Aust 5 months ago
parent
commit
11499b2c09
  1. 1
      Gemfile
  2. 5
      Gemfile.lock
  3. 50
      lib/clover.rb
  4. 5
      spec/spec_helper.rb
  5. 236
      spec/support/clover.xsd

1
Gemfile

@ -9,7 +9,6 @@ gemspec
# Code coverage report
gem 'simplecov', require: false, group: :test
gem 'simplecov-bamboo', require: false, group: :test
# RuboCop support
gem 'rubocop', require: false

5
Gemfile.lock

@ -81,10 +81,6 @@ GEM
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-bamboo (0.1.0)
nokogiri
simplecov
simplecov-html
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
simpleidn (0.2.1)
@ -107,7 +103,6 @@ DEPENDENCIES
rubocop-rspec
sanity!
simplecov
simplecov-bamboo
BUNDLED WITH
2.1.4

50
lib/clover.rb

@ -0,0 +1,50 @@
# frozen_string_literal: true
require 'nokogiri'
require 'pp'
class SimpleCov::Formatter::Clover
def format(result)
SimpleCov::Formatter::HTMLFormatter.new.format(result)
ts = result.created_at.to_i
builder = Nokogiri::XML::Builder.new do |xml|
xml.coverage(generated: ts, clover: "SimpleCov #{SimpleCov::VERSION}") {
xml.project(timestamp: ts) {
xml.metrics(
elements: result.total_lines,
coveredelements: result.covered_lines,
ncloc: result.total_lines
)
xml.package(name: 'All files') {
result.files.each do |file|
xml.file(name: File.basename(file.filename), path:shortened_filename(file)) {
xml.metrics(
classes: 1,
loc: file.lines.count,
ncloc: file.covered_lines.count + file.missed_lines.count
)
file.lines.each do |line|
xml.line(
line: line.number,
type: 'stmt',
count: (line.covered? ? line.coverage : 0)
)
end
}
end
}
}
}
end
File.open(File.join(SimpleCov.coverage_path, 'clover.xml'), 'w') do |f|
f << builder.to_xml
end
end
def shortened_filename(source_file)
source_file.filename.sub(SimpleCov.root, ".").gsub(/^\.\//, "")
end
end

5
spec/spec_helper.rb

@ -1,12 +1,11 @@
# frozen_string_literal: true
require 'simplecov'
require 'simplecov-bamboo'
require 'clover'
SimpleCov.start do
SimpleCov.add_filter 'spec'
SimpleCov.coverage_dir 'coverage'
SimpleCov.formatter = SimpleCov::Formatter::BambooFormatter
SimpleCov.formatter = SimpleCov::Formatter::Clover
end
require 'bundler/setup'

236
spec/support/clover.xsd

@ -0,0 +1,236 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="coverage">
<xs:complexType>
<xs:annotation>
<xs:documentation>
Top-most element describing the coverage report. Contains a
project and a test project.
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element ref="project"/>
<xs:element ref="testproject"/>
</xs:sequence>
<xs:attribute name="clover" use="required" type="xs:NMTOKEN"/>
<xs:attribute name="generated" use="required" type="xs:integer"/>
</xs:complexType>
</xs:element>
<xs:element name="project">
<xs:annotation>
<xs:documentation>
Project metrics relating to non-test source.
@name - project name (optional)
@timestamp - seconds since UTC
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="metrics" type="projectMetrics"/>
<xs:element maxOccurs="unbounded" ref="package"/>
</xs:sequence>
<xs:attribute name="name"/>
<xs:attribute name="timestamp" use="required" type="xs:integer"/>
</xs:complexType>
</xs:element>
<xs:element name="testproject">
<xs:annotation>
<xs:documentation>
Project metrics relating to test source.
@name - project name (optional)
@timestamp - seconds since UTC
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="metrics" type="projectMetrics"/>
<xs:element maxOccurs="unbounded" ref="package"/>
</xs:sequence>
<xs:attribute name="name"/>
<xs:attribute name="timestamp" use="required" type="xs:integer"/>
</xs:complexType>
</xs:element>
<xs:element name="package">
<xs:annotation>
<xs:documentation>
Package metrics.
@name - the.package.name
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="metrics" type="packageMetrics"/>
<xs:element maxOccurs="unbounded" ref="file"/>
</xs:sequence>
<xs:attribute name="name" use="required" type="xs:NCName"/>
</xs:complexType>
</xs:element>
<xs:element name="file">
<xs:annotation>
<xs:documentation>
File metrics.
@name - the file name e.g. Foo.java or Bar.groovy
@path - the filesystem-specific original path to the file e.g. c:\path\to\Bar.groovy
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="metrics" type="fileMetrics"/>
<xs:element maxOccurs="unbounded" ref="class"/>
<xs:element minOccurs="0" maxOccurs="unbounded"
ref="line"/>
</xs:sequence>
<xs:attribute name="name" use="required" type="xs:NCName"/>
<xs:attribute name="path" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="class">
<xs:annotation>
<xs:documentation>
Class metrics.
@name - the unqualified class name
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="metrics" type="classMetrics"/>
</xs:sequence>
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<!-- class name have letters, digits (but not as first character), dollars and underscores -->
<!-- extra: Clover names inner classes as "Outer.Inner" for java and "Outer$Inner" for groovy -->
<xs:pattern value="[\p{L}$_][\p{L}\p{Nd}$_.]+"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="line">
<xs:annotation>
<xs:documentation>
Line-specific information.
@line - the line number
@type - the type of syntactic construct - one of method|stmt|cond
@complexity - only applicable if @type == 'method'; the cyclomatic complexity of the construct
@count - only applicable if @type == 'stmt' or 'method'; the number of times the construct was executed
@truecount - only applicable if @type == 'cond'; the number of times the true branch was executed
@falsecount - only applicable if @type == 'cond'; the number of times the false branch was executed
@signature - only applicable if @type == 'method'; the signature of the method
@testduration - only applicable if @type == 'method' and the method was identified as a test method; the duration of the test
@testsuccess - only applicable if @type == 'method' and the method was identified as a test method; true if the test passed, false otherwise
@visibility - only applicable if @type == 'method'
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="num" use="required" type="xs:integer"/>
<xs:attribute name="type" use="required" type="construct"/>
<xs:attribute name="complexity" type="xs:integer"/>
<xs:attribute name="count" type="xs:integer"/>
<xs:attribute name="falsecount" type="xs:integer"/>
<xs:attribute name="truecount" type="xs:integer"/>
<xs:attribute name="signature" type="xs:string"/>
<xs:attribute name="testduration" type="xs:decimal"/>
<xs:attribute name="testsuccess" type="xs:boolean"/>
<xs:attribute name="visibility" type="visibility"/>
</xs:complexType>
</xs:element>
<xs:complexType name="classMetrics">
<xs:annotation>
<xs:documentation>
Metrics information for projects/packages/files/classes.
@complexity - the cyclomatic complexity
@conditionals - the number of contained conditionals (2 * number of branches)
@coveredconditionals - the number of contained conditionals (2 * number of branches) with coverage
@elements - the number of contained statements, conditionals and methods
@coveredelements - the number of contained statements, conditionals and methods with coverage
@statements - the number of contained statements
@coveredstatements - the number of contained statements with coverage
@methods - the number of contained methods
@coveredmethods - the number of contained methods with coverage
@testduration - the total duration of all contained test methods
@testfailures - the total number of test method failures
@testpasses - the total number of test method passes
@testruns - the total number of test methods run
</xs:documentation>
</xs:annotation>
<xs:attribute name="complexity" use="required" type="xs:integer"/>
<xs:attribute name="elements" use="required" type="xs:integer"/>
<xs:attribute name="coveredelements" use="required" type="xs:integer"/>
<xs:attribute name="conditionals" use="required" type="xs:integer"/>
<xs:attribute name="coveredconditionals" use="required"
type="xs:integer"/>
<xs:attribute name="statements" use="required" type="xs:integer"/>
<xs:attribute name="coveredstatements" use="required"
type="xs:integer"/>
<xs:attribute name="coveredmethods" use="required" type="xs:integer"/>
<xs:attribute name="methods" use="required" type="xs:integer"/>
<xs:attribute name="testduration" type="xs:decimal"/>
<xs:attribute name="testfailures" type="xs:integer"/>
<xs:attribute name="testpasses" type="xs:integer"/>
<xs:attribute name="testruns" type="xs:integer"/>
</xs:complexType>
<xs:complexType name="fileMetrics">
<xs:annotation>
<xs:documentation>
Metrics information for projects/packages/files.
@classes - the total number of contained classes
@loc - the total number of lines of code
@ncloc - the total number of non-comment lines of code
</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="classMetrics">
<xs:attribute name="classes" type="xs:integer"/>
<xs:attribute name="loc" type="xs:integer"/>
<xs:attribute name="ncloc" type="xs:integer"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="packageMetrics">
<xs:annotation>
<xs:documentation>
Metrics information for projects/packages.
@files - the total number of contained files
</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="fileMetrics">
<xs:attribute name="files" type="xs:integer"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="projectMetrics">
<xs:annotation>
<xs:documentation>
Metrics information for projects.
@files - the total number of packages
</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="packageMetrics">
<xs:attribute name="packages" type="xs:integer"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:simpleType name="construct">
<xs:restriction base="xs:string">
<xs:enumeration value="method"/>
<xs:enumeration value="stmt"/>
<xs:enumeration value="cond"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="visibility">
<xs:restriction base="xs:string">
<xs:enumeration value="private"/>
<xs:enumeration value="protected"/>
<xs:enumeration value="package"/>
<xs:enumeration value="public"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Loading…
Cancel
Save