gcov2x 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/.travis.yml +3 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +38 -0
- data/LICENSE +22 -0
- data/README.md +25 -0
- data/Rakefile +2 -0
- data/bin/gcov2x +101 -0
- data/gcov2x.gemspec +15 -0
- data/lib/ansii_formatter.rb +34 -0
- data/lib/file.rb +84 -0
- data/lib/gcov2x.rb +4 -0
- data/lib/html_formatter.rb +68 -0
- data/lib/html_view.html.erb +186 -0
- data/lib/line.rb +37 -0
- data/lib/project.rb +65 -0
- data/lib/version.rb +3 -0
- data/lib/xml_formatter.rb +58 -0
- data/spec/data/data2/test3.cpp.gcov +22 -0
- data/spec/data/test.cpp.gcov +14 -0
- data/spec/data/test1.cpp.gcov +21 -0
- data/spec/data/test2.cpp.gcov +22 -0
- data/spec/file_spec.rb +73 -0
- data/spec/line_spec.rb +49 -0
- data/spec/project_spec.rb +84 -0
- data/spec/spec_helper.rb +8 -0
- data/src/Makefile +33 -0
- data/src/test.cpp +9 -0
- data/src/test.h +7 -0
- data/src/test1.cpp +16 -0
- data/src/test2.cpp +17 -0
- data/src/test3.cpp +17 -0
- data/tasks/rubygems.rake +3 -0
- data/tasks/spec.rake +8 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 86e9963bfe5c1d5e50a80853ce8e9772123efd9f
|
4
|
+
data.tar.gz: 7c201f588c22f3f5c2296e3e45874518cf084ad8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2551f66a91913ef11c5a54e877bb7801a7ced9b320e1349a51505deaa09d226c09402aa9d4131f7735031b62f62257184d4102cfc5bff8400357fe7b5d054d4
|
7
|
+
data.tar.gz: 57b0e1c8d95ccc1ae41eb0859abbe792306da800f953a6c42139e33e9868d8c33576bc82dd153ebeae2d2c2dc63b310058d8fbad34652772a6dfb40928861332
|
data/.gitignore
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
35
|
+
|
36
|
+
## Emacs
|
37
|
+
*~
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
builder (3.2.2)
|
5
|
+
diff-lcs (1.2.5)
|
6
|
+
gyoku (1.2.2)
|
7
|
+
builder (>= 2.1.2)
|
8
|
+
mixlib-cli (1.5.0)
|
9
|
+
rake (10.3.2)
|
10
|
+
rspec (3.1.0)
|
11
|
+
rspec-core (~> 3.1.0)
|
12
|
+
rspec-expectations (~> 3.1.0)
|
13
|
+
rspec-mocks (~> 3.1.0)
|
14
|
+
rspec-core (3.1.7)
|
15
|
+
rspec-support (~> 3.1.0)
|
16
|
+
rspec-expectations (3.1.2)
|
17
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
18
|
+
rspec-support (~> 3.1.0)
|
19
|
+
rspec-mocks (3.1.3)
|
20
|
+
rspec-support (~> 3.1.0)
|
21
|
+
rspec-support (3.1.2)
|
22
|
+
rubygems-tasks (0.2.4)
|
23
|
+
term-ansicolor (1.3.0)
|
24
|
+
tins (~> 1.0)
|
25
|
+
terminal-table (1.4.5)
|
26
|
+
tins (1.3.3)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
gyoku (~> 1.0)
|
33
|
+
mixlib-cli
|
34
|
+
rake
|
35
|
+
rspec
|
36
|
+
rubygems-tasks
|
37
|
+
term-ansicolor
|
38
|
+
terminal-table
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Mattias Bergbom
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
gcov2x
|
2
|
+
======
|
3
|
+
|
4
|
+
![Travis CI Status](https://travis-ci.org/mattiasbergbom/gcov2x.svg)
|
5
|
+
|
6
|
+
**gcov2x** takes coverage data emitted from [llvm-cov](http://llvm.org/docs/CommandGuide/llvm-cov.html) and aggregates it into various formats, some more easily interpreted by humans, some better suited for machines.
|
7
|
+
|
8
|
+
Quick Start
|
9
|
+
-----------
|
10
|
+
|
11
|
+
First, unless you haven't already done so, compile your project using ```clang --coverage``` and digest the output using ```llvm-cov``` (see the `src` dir for examples). You should end up with one or more ```.gcov``` files.
|
12
|
+
|
13
|
+
Next, install the gem:
|
14
|
+
|
15
|
+
```gem install gcov2x```
|
16
|
+
|
17
|
+
This should furnish you with a ```gcov2x``` executable in your path.
|
18
|
+
|
19
|
+
Finally, execute ```gcov2x``` in one of multiple possible ways. For instance, generate a HTML coverage report:
|
20
|
+
|
21
|
+
```gcov2x --format html *.gcov > coverage.html```
|
22
|
+
|
23
|
+
Disclaimer
|
24
|
+
----------
|
25
|
+
This is a work in progress.
|
data/Rakefile
ADDED
data/bin/gcov2x
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'mixlib/cli'
|
4
|
+
|
5
|
+
require_relative '../lib/gcov2x'
|
6
|
+
require_relative '../lib/ansii_formatter'
|
7
|
+
require_relative '../lib/xml_formatter'
|
8
|
+
require_relative '../lib/html_formatter'
|
9
|
+
|
10
|
+
class Util
|
11
|
+
def Util.opt_wrap(s, width=61)
|
12
|
+
s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n ")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class CGOV_CLI
|
17
|
+
include Mixlib::CLI
|
18
|
+
|
19
|
+
option :filter,
|
20
|
+
:long => "--filter FILTER",
|
21
|
+
:description => Util.opt_wrap("A regex filter which specifies which files not to include in the conversion. Will filter on the actual filename (replacing any mangling done by llvm-cov using #'s) as well as the 'Source' meta attribute in the GCOV data. Available presets:
|
22
|
+
xcode - Xcode system headers
|
23
|
+
linux - Linux system headers
|
24
|
+
"),
|
25
|
+
:proc => Proc.new { |f| (f.size > 0 and f[0] == ":" ? f[1..-1].to_sym : f ) }
|
26
|
+
|
27
|
+
option :format,
|
28
|
+
:short => "-f FORMAT",
|
29
|
+
:long => "--format FORMAT",
|
30
|
+
:description => Util.opt_wrap("The output format (ascii, html, xml, json)"),
|
31
|
+
:proc => Proc.new { |f| f.to_sym }
|
32
|
+
|
33
|
+
option :css,
|
34
|
+
:short => "-c CSS",
|
35
|
+
:long => "--css CSS",
|
36
|
+
:description => Util.opt_wrap("CSS file to reference in HTML output.")
|
37
|
+
|
38
|
+
option :xsl,
|
39
|
+
:short => "-x XSL",
|
40
|
+
:long => "--xsl XSL",
|
41
|
+
:description => Util.opt_wrap("XSL file to reference in XML output.")
|
42
|
+
|
43
|
+
option :recursive,
|
44
|
+
:short => "-r",
|
45
|
+
:long => "--recursive",
|
46
|
+
:description => Util.opt_wrap("Recursively load all .gcov files in the given directory"),
|
47
|
+
:on => :tail,
|
48
|
+
:boolean => true
|
49
|
+
|
50
|
+
option :help,
|
51
|
+
:short => "-h",
|
52
|
+
:long => "--help",
|
53
|
+
:description => Util.opt_wrap("Show this message"),
|
54
|
+
:on => :tail,
|
55
|
+
:boolean => true,
|
56
|
+
:show_options => true,
|
57
|
+
:exit => 0
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
cli = CGOV_CLI.new
|
62
|
+
filenames = cli.parse_options
|
63
|
+
|
64
|
+
fail "Got no filename" unless filenames.is_a? Array and filenames.count > 0
|
65
|
+
|
66
|
+
STDERR.puts "filter: #{cli.config[:filter]}"
|
67
|
+
|
68
|
+
proj = GCOV::Project.new
|
69
|
+
|
70
|
+
filter = case cli.config[:filter]
|
71
|
+
when :xcode then /Developer\/Toolchains\/.*\/usr\/include\//
|
72
|
+
when :linux then /\/usr\/include\//
|
73
|
+
else /#{cli.config[:filter]}/
|
74
|
+
end
|
75
|
+
|
76
|
+
STDERR.puts "filter regex: #{filter}"
|
77
|
+
|
78
|
+
filenames.each do |filename|
|
79
|
+
if File.directory? filename
|
80
|
+
proj.add_dir filename, :recursive => cli.config[:recursive], :filter => filter
|
81
|
+
elsif File.file? filename
|
82
|
+
proj.add_file filename, :filter => filter
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
case cli.config[:format]
|
87
|
+
when :ascii then
|
88
|
+
formatter = GCOV::ANSIIFormatter.new proj
|
89
|
+
formatter.print
|
90
|
+
when :html then
|
91
|
+
formatter = GCOV::HTMLFormatter.new( proj, :css => cli.config[:css] )
|
92
|
+
formatter.print
|
93
|
+
when :xml then
|
94
|
+
formatter = GCOV::XMLFormatter.new( proj, :xsl => cli.config[:xsl] )
|
95
|
+
formatter.print
|
96
|
+
when :json then
|
97
|
+
fail "json export not implemented yet"
|
98
|
+
else
|
99
|
+
fail "Invalid format"
|
100
|
+
end
|
101
|
+
|
data/gcov2x.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../lib/version.rb', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'gcov2x'
|
5
|
+
gem.version = GCOV::VERSION
|
6
|
+
gem.date = '2014-12-09'
|
7
|
+
gem.summary = "gcov parser and formatter"
|
8
|
+
gem.description = "gcov2x digests .gcov files generated by llvm-cov and translates them into various common formats"
|
9
|
+
gem.authors = ["Mattias Bergbom"]
|
10
|
+
gem.email = 'mattias.bergbom@gmail.com'
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = ["gcov2x"]
|
13
|
+
gem.homepage = 'http://rubygems.org/gems/gcov2x'
|
14
|
+
gem.license = 'MIT'
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'term/ansicolor'
|
2
|
+
include Term::ANSIColor
|
3
|
+
|
4
|
+
require_relative './project'
|
5
|
+
require_relative './file'
|
6
|
+
require_relative './line'
|
7
|
+
|
8
|
+
module GCOV
|
9
|
+
|
10
|
+
class ANSIIFormatter
|
11
|
+
|
12
|
+
def initialize project
|
13
|
+
@project = project
|
14
|
+
end
|
15
|
+
|
16
|
+
def print
|
17
|
+
|
18
|
+
@project.files.each do |file|
|
19
|
+
puts "#{white}#{bold}=== #{file.meta['Source']} ===#{reset}"
|
20
|
+
file.lines.select{|line| line.number > 0}.each do |line|
|
21
|
+
col = case line.count
|
22
|
+
when :none then dark+white
|
23
|
+
when :missed then black+on_red
|
24
|
+
else green
|
25
|
+
end
|
26
|
+
puts col + line.text + reset
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/file.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require_relative './line'
|
2
|
+
|
3
|
+
class TrueClass
|
4
|
+
def to_i
|
5
|
+
return 1
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class FalseClass
|
10
|
+
def to_i
|
11
|
+
return 0
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module GCOV
|
16
|
+
|
17
|
+
class File
|
18
|
+
|
19
|
+
attr_reader :name, :lines, :meta, :stats
|
20
|
+
|
21
|
+
def initialize name
|
22
|
+
fail "name required" unless name and name.is_a? String
|
23
|
+
@name = name
|
24
|
+
@lines = []
|
25
|
+
@meta = {}
|
26
|
+
@stats = {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_lines &block
|
30
|
+
fail "add_lines requires a block" unless block_given?
|
31
|
+
@adding = true
|
32
|
+
yield
|
33
|
+
@adding = false
|
34
|
+
_update_stats
|
35
|
+
end
|
36
|
+
|
37
|
+
def _update_stats
|
38
|
+
@stats = {
|
39
|
+
:missed_lines => 0,
|
40
|
+
:exec_lines => 0,
|
41
|
+
:empty_lines => 0,
|
42
|
+
:total_exec => 0,
|
43
|
+
:total_lines => 0,
|
44
|
+
:lines => 0,
|
45
|
+
:coverage => 0.0
|
46
|
+
}
|
47
|
+
|
48
|
+
@lines.each do |line|
|
49
|
+
@stats[:missed_lines] += (line.state == :missed).to_i
|
50
|
+
@stats[:exec_lines] += (line.state == :exec).to_i
|
51
|
+
@stats[:total_exec] += (line.count.is_a?(Integer) ? line.count : 0 )
|
52
|
+
@stats[:empty_lines] += (line.state == :none).to_i
|
53
|
+
end
|
54
|
+
|
55
|
+
@stats[:lines] = @stats[:exec_lines] + @stats[:missed_lines]
|
56
|
+
@stats[:total_lines] = @stats[:lines] + @stats[:empty_lines]
|
57
|
+
@stats[:coverage] = @stats[:exec_lines].to_f / @stats[:lines].to_f
|
58
|
+
@stats[:coverage_s] = sprintf("%0.01f%",100.0*@stats[:coverage])
|
59
|
+
end
|
60
|
+
|
61
|
+
def <<(line)
|
62
|
+
fail "need to be in add_lines block" unless @adding
|
63
|
+
if line.number == 0
|
64
|
+
key,val = /([^:]+):(.*)$/.match(line.text).to_a[1..2]
|
65
|
+
@meta[key] = val
|
66
|
+
else
|
67
|
+
@lines << line
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.load filename
|
72
|
+
file = GCOV::File.new filename
|
73
|
+
::File.open(filename, "r") do |file_handle|
|
74
|
+
file.add_lines do
|
75
|
+
file_handle.each_line do |line|
|
76
|
+
file << GCOV::Line.parse(line)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
file
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
data/lib/gcov2x.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
require_relative './project'
|
3
|
+
require_relative './file'
|
4
|
+
require_relative './line'
|
5
|
+
|
6
|
+
require 'erb'
|
7
|
+
require 'cgi'
|
8
|
+
|
9
|
+
module GCOV
|
10
|
+
|
11
|
+
class HTMLFormatter
|
12
|
+
|
13
|
+
def get_binding # this is only a helper method to access the objects binding method
|
14
|
+
binding
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize project, va={}
|
18
|
+
@project = project
|
19
|
+
@css = va[:css]
|
20
|
+
|
21
|
+
if !@css
|
22
|
+
@csslink = <<EOF
|
23
|
+
<style>
|
24
|
+
|
25
|
+
</style>
|
26
|
+
EOF
|
27
|
+
else
|
28
|
+
@csslink = "<link rel=\"stylesheet\" href=\"#{@css}\" />"
|
29
|
+
end
|
30
|
+
|
31
|
+
@template = ::File.read(::File.join(::File.dirname(__FILE__),"html_view.html.erb"))
|
32
|
+
end # initialize
|
33
|
+
|
34
|
+
def class_of line
|
35
|
+
case line.count
|
36
|
+
when :none then "moot"
|
37
|
+
when :missed then "missed"
|
38
|
+
else "ok"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def class_of_stat value, &block
|
43
|
+
fail "class_of_stat needs a block" unless block_given?
|
44
|
+
return ( (yield value) ? "value" : "value_bad" )
|
45
|
+
end
|
46
|
+
|
47
|
+
def class_of_file file
|
48
|
+
case file.stats[:missed_lines]
|
49
|
+
when 0 then "header good"
|
50
|
+
else "header bad"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def encode text
|
55
|
+
CGI.escapeHTML( text )
|
56
|
+
end
|
57
|
+
|
58
|
+
def print
|
59
|
+
|
60
|
+
renderer = ERB.new( @template )
|
61
|
+
|
62
|
+
puts renderer.result(self.get_binding)
|
63
|
+
|
64
|
+
end # HTMLFormatter#print
|
65
|
+
|
66
|
+
end # HTMLFormatter
|
67
|
+
|
68
|
+
end # GCOV
|