gcov2x 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc193fe4a3be29c0863a092df1ada25ab1ffb660
4
- data.tar.gz: 5608d02ef2b141296b09cf08de5b7bc76473d8f4
3
+ metadata.gz: 740237ee0abec57ac7be4ed0fed51ef80f4f8f17
4
+ data.tar.gz: 047ebd3dbd900b8f3e15e0628c45ef68d0eadcc3
5
5
  SHA512:
6
- metadata.gz: bb6c7cf682665c724e8d1dfd273990dbd14e7a3fc9b296f56bd8e644cece9363f6e7d694b9314f14b6bd2961ae9014f1e43e2cbc2d0cd69584cacc8890a123da
7
- data.tar.gz: d2be48bb64447d436613d47ad06a3088e3a39a8b1633cbb7276d8ab78735e1f9852cc0f2512ce481d26d9b27bf25ab802d00aab3e49e4f70a54fc69308dfcbc3
6
+ metadata.gz: 40f12f5c19bbfa268264084d33095a9b2212e0f6861bfdabeb0458c642a82d32be8a482d2e92cf0b8125dc1495b4e428251f96d4bcab09f9a19de94df2559aa6
7
+ data.tar.gz: bbd4542d5b4c06ab00269cb546838215147f60dac19b0b3e171fcac965242d2b05c3168cf72806df82208f797329600058d5e8ab043f4f46b1583923210e2a4b
data/lib/file.rb CHANGED
@@ -22,12 +22,17 @@ module GCOV
22
22
  def initialize name
23
23
  fail "name required" unless name and name.is_a? String
24
24
  @name = name
25
- @lines = []
25
+ @lines = {}
26
26
  @meta = {}
27
27
  @stats = {}
28
28
  _update_stats
29
29
  end
30
30
 
31
+ # return lines as array, in order by number
32
+ def lines
33
+ @lines.sort.map{|key,val|val}
34
+ end
35
+
31
36
  def add_lines &block
32
37
  fail "add_lines requires a block" unless block_given?
33
38
  @adding = true
@@ -48,7 +53,7 @@ module GCOV
48
53
  :hits_per_line => 0.0
49
54
  }
50
55
 
51
- @lines.each do |line|
56
+ @lines.each do |index,line|
52
57
  @stats[:missed_lines] += (line.state == :missed).to_i
53
58
  @stats[:exec_lines] += (line.state == :exec).to_i
54
59
  @stats[:total_exec] += (line.count.is_a?(Integer) ? line.count : 0 )
@@ -76,7 +81,7 @@ module GCOV
76
81
  key,val = /([^:]+):(.*)$/.match(line.text).to_a[1..2]
77
82
  @meta[key] = val
78
83
  else
79
- @lines << line
84
+ @lines[line.number] = line
80
85
  end
81
86
  end
82
87
 
@@ -122,6 +127,23 @@ module GCOV
122
127
  result
123
128
  end
124
129
 
130
+ def merge! other
131
+ other.lines.each do |line|
132
+ if @lines.has_key? line.number
133
+ @lines[line.number].merge! line
134
+ else
135
+ @lines[line.number] = line
136
+ end
137
+ end
138
+ _update_stats
139
+ end
140
+
141
+ def merge other
142
+ result = self.dup
143
+ result.merge! other
144
+ result
145
+ end
146
+
125
147
  end # class File
126
148
 
127
149
  end
data/lib/line.rb CHANGED
@@ -3,17 +3,20 @@ module GCOV
3
3
 
4
4
  class Line
5
5
 
6
- attr_reader :number, :count, :text, :state
6
+ attr_reader :number, :count, :text
7
7
 
8
8
  def initialize number, count, text
9
9
  @number = number
10
10
  @count = count
11
11
  @text = text
12
- @state = case @count
13
- when :missed then :missed
14
- when :none then :none
15
- else :exec
16
- end
12
+ end
13
+
14
+ def state
15
+ case @count
16
+ when :missed then :missed
17
+ when :none then :none
18
+ else :exec
19
+ end
17
20
  end
18
21
 
19
22
  def self.parse line
@@ -29,6 +32,24 @@ module GCOV
29
32
  GCOV::Line.new number,count,text
30
33
  end
31
34
 
35
+ def merge! other
36
+ if other.count.is_a? Integer and @count.is_a? Integer
37
+ @count += other.count
38
+ elsif other.count.is_a? Integer
39
+ @count = other.count
40
+ elsif @count.is_a? Integer
41
+ nil
42
+ elsif other.count == :missed or @count == :missed
43
+ @count = :missed
44
+ end
45
+ end
46
+
47
+ def merge other
48
+ result = self.dup
49
+ result.merge! other
50
+ result
51
+ end
52
+
32
53
  end
33
54
 
34
55
  end
data/lib/project.rb CHANGED
@@ -10,15 +10,30 @@ module GCOV
10
10
 
11
11
  def initialize name=""
12
12
  @name = name
13
- @files = []
13
+ @files = {}
14
14
  @adding = false
15
15
  end
16
16
 
17
17
  def <<(file)
18
- @files << file
18
+ if @files.has_key?file.name
19
+ @files[file.name].merge! file
20
+ else
21
+ @files[file.name] = file
22
+ end
19
23
  _update_stats unless @adding
20
24
  end
21
25
 
26
+ def files
27
+ @files.sort{|a,b|
28
+ if ::File.basename(a[0]) < ::File.basename(b[0])
29
+ -1
30
+ elsif ::File.basename(a[0]) == ::File.basename(b[0])
31
+ 0
32
+ else
33
+ 1
34
+ end }.map{|key,val|val}
35
+ end
36
+
22
37
  def add_files &block
23
38
  # suspend stat updates until done adding files
24
39
  fail "add_files requires a block" unless block_given?
@@ -45,7 +60,7 @@ module GCOV
45
60
  :hits_per_line => 0
46
61
  }
47
62
 
48
- @files.each do |file|
63
+ @files.each do |name,file|
49
64
  @stats[:missed_lines] += file.stats[:missed_lines]
50
65
  @stats[:exec_lines] += file.stats[:exec_lines]
51
66
  @stats[:total_exec] += file.stats[:total_exec]
@@ -68,39 +83,44 @@ module GCOV
68
83
 
69
84
  end
70
85
 
71
- def add_dir path, hash={}
72
- add_files do
73
- if hash[:recursive] == true
74
- filenames = Dir["#{path}/**/*.gcov"]
75
- else
76
- filenames = Dir["#{path}/*.gcov"]
77
- end
86
+ def _add_file path, hash_={}
87
+ hash = hash_.dup
88
+
89
+ # legacy support
90
+ if !hash[:filter].nil? and ( hash[:filter].is_a? Regexp )
91
+ hash[:filter] = [ hash[:filter] ]
92
+ end
93
+
94
+ files = GCOV::File.load(path)
78
95
 
79
- # legacy support
80
- if !hash[:filter].nil? and ( hash[:filter].is_a? Regexp )
81
- hash[:filter] = [ hash[:filter] ]
82
- end
83
-
84
- filenames.map{|filename| GCOV::File.load filename }.each do |files|
85
- files.each do |file|
86
- if hash[:filter].nil? or hash[:filter].empty? or hash[:filter].select{|f| f.match(::Pathname.new(file.meta['Source']).cleanpath.to_s) }.empty?
87
- self << file
88
- end # if
89
- end # each file
90
- end # each files
96
+ files.each do |file|
97
+ if hash[:filter].nil? or hash[:filter].empty? or hash[:filter].select{|f| f.match(::Pathname.new(file.meta['Source']).cleanpath.to_s) }.empty?
98
+ self << file
99
+ end # if
100
+ end #each file
101
+ end
102
+
103
+ def add_dir path, hash_={}
104
+ hash = hash_.dup
105
+ if hash[:recursive] == true
106
+ filenames = Dir["#{path}/**/*.gcov"]
107
+ else
108
+ filenames = Dir["#{path}/*.gcov"]
109
+ end
110
+
111
+ add_files do
112
+ filenames.each do |filename|
113
+ _add_file filename, hash
114
+ end # each filename
91
115
  end # add_files
92
116
  end # #add_dir
93
-
94
- def add_file path, hash={}
117
+
118
+ def add_file path, hash_={}
119
+ hash = hash_.dup
95
120
  add_files do
96
- files = GCOV::File.load(path)
97
- files.each do |file|
98
- if hash[:filter].nil? or hash[:filter].empty? or hash[:filter].select{|f| f.match(::Pathname.new(file.meta['Source']).cleanpath.to_s) }.empty?
99
- self << file
100
- end # if
101
- end # each file
121
+ _add_file path, hash
102
122
  end # add_files
103
- end # add_file
123
+ end # #add_file
104
124
 
105
125
  def self.load_dir path, hash={}
106
126
  project = GCOV::Project.new
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GCOV
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
@@ -62,11 +62,11 @@ describe GCOV::File do
62
62
  expect(file.lines.count).to eq(0)
63
63
  end
64
64
 
65
- it "returns the lines it was given" do
65
+ it "should return the lines it was given, sorted by number" do
66
66
  file = GCOV::File.new "myfile.cpp"
67
67
  file.add_lines do
68
- file << GCOV::Line.new(1,4,"line 1")
69
68
  file << GCOV::Line.new(2,23,"line 2")
69
+ file << GCOV::Line.new(1,4,"line 1")
70
70
  end
71
71
  expect(file.lines.count).to eq(2)
72
72
  expect(file.lines[0].number).to eq(1)
@@ -103,4 +103,38 @@ describe GCOV::File do
103
103
  end
104
104
  end
105
105
 
106
+ describe "#merge" do
107
+
108
+ it "should merge the counts of each line and recompute stats" do
109
+ file = GCOV::File.new "myfile.cpp"
110
+ file.add_lines do
111
+ file << GCOV::Line.new(1,4,"line 1")
112
+ file << GCOV::Line.new(2,23,"line 2")
113
+ file << GCOV::Line.new(3,:none,"line 3")
114
+ file << GCOV::Line.new(4,:missed,"line 4")
115
+ file << GCOV::Line.new(5,:missed,"line 5")
116
+ end
117
+
118
+ file2 = GCOV::File.new "myfile.cpp"
119
+ file2.add_lines do
120
+ file2 << GCOV::Line.new(1,1,"line 1")
121
+ file2 << GCOV::Line.new(2,:missed,"line 2")
122
+ file2 << GCOV::Line.new(3,:none,"line 3")
123
+ file2 << GCOV::Line.new(4,4,"line 4")
124
+ file2 << GCOV::Line.new(5,:missed,"line 5")
125
+ end
126
+
127
+ file3 = file.merge file2
128
+
129
+ expect(file3.stats[:lines]).to eq(4)
130
+ expect(file3.stats[:total_lines]).to eq(5)
131
+ expect(file3.stats[:total_exec]).to eq(32)
132
+ expect(file3.stats[:empty_lines]).to eq(1)
133
+ expect(file3.stats[:exec_lines]).to eq(3)
134
+ expect(file3.stats[:missed_lines]).to eq(1)
135
+ expect(file3.stats[:coverage]).to eq(0.75)
136
+ expect(file3.stats[:hits_per_line]).to eq(32.0/4)
137
+
138
+ end # it
139
+ end # describe
106
140
  end
@@ -46,4 +46,48 @@ describe GCOV::Line do
46
46
 
47
47
  end
48
48
 
49
+ describe "#state" do
50
+ it "should return :exec if it has positive count" do
51
+ line = GCOV::Line.new 3,5,"line x"
52
+ expect(line.state).to eq(:exec)
53
+ end
54
+
55
+ it "should return :missed if it was missed" do
56
+ line = GCOV::Line.new 3,:missed,"line x"
57
+ expect(line.state).to eq(:missed)
58
+ end
59
+
60
+ it "should return :none if it is not relevant" do
61
+ line = GCOV::Line.new 3,:none,"line x"
62
+ expect(line.state).to eq(:none)
63
+ end
64
+ end
65
+
66
+ describe "#merge" do
67
+ it "should add hit counts" do
68
+ line = GCOV::Line.new 3,4, "abcdef"
69
+ line2 = GCOV::Line.new 3,1, "abcdef"
70
+ line3 = line.merge line2
71
+ expect(line3.count).to eq(5)
72
+
73
+ line = GCOV::Line.new 3,:missed, "abcdef"
74
+ line2 = GCOV::Line.new 3,1, "abcdef"
75
+ line3 = line.merge line2
76
+ expect(line3.count).to eq(1)
77
+
78
+ line = GCOV::Line.new 3,1, "abcdef"
79
+ line2 = GCOV::Line.new 3,:missed, "abcdef"
80
+ line3 = line.merge line2
81
+ expect(line3.count).to eq(1)
82
+ end
83
+
84
+ it "should give missed (0) presedence over none" do
85
+ line = GCOV::Line.new 3,:missed, "abcdef"
86
+ line2 = GCOV::Line.new 3,:none, "abcdef"
87
+ line3 = line.merge line2
88
+ expect(line3.count).to eq(:missed)
89
+ end
90
+
91
+ end # describe #merge
92
+
49
93
  end
@@ -32,8 +32,8 @@ describe GCOV::Project do
32
32
  project << GCOV::File.new("foobar.cpp")
33
33
  project << GCOV::File.new("boofar.cpp")
34
34
  expect(project.files.count).to eq(2)
35
- expect(project.files[0].name).to eq("foobar.cpp")
36
- expect(project.files[1].name).to eq("boofar.cpp")
35
+ expect(project.files.map(&:name)).to include(a_string_ending_with("foobar.cpp"))
36
+ expect(project.files.map(&:name)).to include(a_string_ending_with("boofar.cpp"))
37
37
  end
38
38
  end
39
39
 
@@ -55,7 +55,7 @@ describe GCOV::Project do
55
55
  end
56
56
 
57
57
  describe "#add_file" do
58
- it "adds the given file" do
58
+ it "should add the given file" do
59
59
  project = GCOV::Project.new
60
60
  project.add_file(File.join(File.dirname(__FILE__),"data","test2.cpp.gcov"))
61
61
  expect(project.files.count).to eq(1)
@@ -70,7 +70,6 @@ describe GCOV::Project do
70
70
  expect(project.files.map(&:name)).to include( "test1.cpp" )
71
71
  end
72
72
 
73
-
74
73
  it "should filter using given array of expressions" do
75
74
  project = GCOV::Project.new
76
75
  project.add_file(File.join(File.dirname(__FILE__),"data","test2.cpp.gcov"), :filter => [/test2\.cpp/,/test3\.cpp/])
@@ -92,7 +91,40 @@ describe GCOV::Project do
92
91
  expect(project.files.map(&:name)).to include( a_string_ending_with("test.cpp") )
93
92
  expect(project.files.map(&:name)).to include( a_string_ending_with("test1.cpp") )
94
93
  end
95
- end
94
+
95
+ it "should merge file stats for identical filenames" do
96
+ project = GCOV::Project.new
97
+ project.add_files do
98
+ file = GCOV::File.new "myfile.cpp"
99
+ file.add_lines do
100
+ file << GCOV::Line.new(0,:none,"Source:myfile.cpp")
101
+ file << GCOV::Line.new(1,4,"line 1")
102
+ file << GCOV::Line.new(2,23,"line 2")
103
+ file << GCOV::Line.new(3,:none,"line 3")
104
+ file << GCOV::Line.new(4,:missed,"line 4")
105
+ file << GCOV::Line.new(5,:none,"line 5")
106
+ end
107
+
108
+ project << file
109
+
110
+ file = GCOV::File.new "myfile.cpp"
111
+ file.add_lines do
112
+ file << GCOV::Line.new(0,:none,"Source:myfile.cpp")
113
+ file << GCOV::Line.new(1,:missed,"line 1")
114
+ file << GCOV::Line.new(2,40,"line 2")
115
+ file << GCOV::Line.new(3,:none,"line 3")
116
+ file << GCOV::Line.new(4,:none,"line 4")
117
+ end
118
+
119
+ project << file
120
+
121
+ end # add_files
122
+
123
+ expect(project.files.count).to eq(1)
124
+
125
+ end # it
126
+
127
+ end # describe
96
128
 
97
129
  describe "#add_dir" do
98
130
  it "adds all files in the given directory" do
@@ -162,7 +194,7 @@ describe GCOV::Project do
162
194
 
163
195
  project << file
164
196
 
165
- file = GCOV::File.new "myfile.cpp"
197
+ file = GCOV::File.new "myfile2.cpp"
166
198
  file.add_lines do
167
199
  file << GCOV::Line.new(1,:missed,"line 1")
168
200
  file << GCOV::Line.new(2,40,"line 2")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcov2x
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattias Bergbom