simplecov-reports 0.0.4.ooyala

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.
Files changed (39) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +7 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +66 -0
  6. data/Rakefile +73 -0
  7. data/lib/simplecov-html-extended.rb +50 -0
  8. data/lib/simplecov/configuration.rb +98 -0
  9. data/lib/simplecov/reports.rb +5 -0
  10. data/lib/simplecov/reports/author_report.rb +180 -0
  11. data/lib/simplecov/reports/file_report.rb +97 -0
  12. data/lib/simplecov/reports/version.rb +5 -0
  13. data/lib/simplecov/source_file.rb +39 -0
  14. data/simplecov-reports.gemspec +29 -0
  15. data/test/fixtures/author_report/author_stats_file1.rb +23 -0
  16. data/test/fixtures/author_report/author_stats_file2.rb +26 -0
  17. data/test/fixtures/author_report/best_author_tolerance.rb +264 -0
  18. data/test/fixtures/file_report/classes_covered.rb +80 -0
  19. data/test/fixtures/file_report/classes_not_covered.rb +37 -0
  20. data/test/fixtures/file_report/classes_partially_covered.rb +11 -0
  21. data/test/fixtures/file_report/methods_covered.rb +38 -0
  22. data/test/fixtures/file_report/methods_not_covered.rb +39 -0
  23. data/test/fixtures/file_report/methods_partially_covered.rb +13 -0
  24. data/test/fixtures/line enhancer/line_enhancer_fixture.rb +1 -0
  25. data/test/helper.rb +19 -0
  26. data/test/memory_measure.rb +0 -0
  27. data/test/test_all_reports.rb +35 -0
  28. data/test/test_author_stats.rb +89 -0
  29. data/test/test_best_author_stage1.rb +75 -0
  30. data/test/test_best_author_stage2.rb +75 -0
  31. data/test/test_best_author_stage3.rb +86 -0
  32. data/test/test_best_author_stage4.rb +97 -0
  33. data/test/test_best_author_stage5.rb +97 -0
  34. data/test/test_file_reports.rb +159 -0
  35. data/test/test_html_reports.rb +43 -0
  36. data/test/test_line_enhancer.rb +26 -0
  37. data/views/author_report.erb +37 -0
  38. data/views/file_report.erb +21 -0
  39. metadata +203 -0
@@ -0,0 +1,97 @@
1
+ #
2
+ # FileReport gives statistics of different types of elements based on analyzing the code in files.
3
+ # Stats are generated per file, but also summarized for the element of interest.
4
+ # The elements are for example, 'api' calls. 'class'es and 'method's.
5
+ #
6
+ require "simplecov"
7
+
8
+ module SimpleCov
9
+ class FileReport < Report
10
+ BLOCK_END_REGEX = /^(?<indent>\s*)end\s*$/
11
+
12
+ attr_reader :report_type, :title, :options
13
+
14
+ def initialize(options)
15
+ @options = options
16
+ @report_type = options[:report_type]
17
+ case @report_type
18
+ when :api
19
+ @block_start_regex = /^(?<indent>\s*)(get|put|post|delete|patch|options|before) \"/
20
+ @title = "API methods missing coverage"
21
+ when :class
22
+ @block_start_regex = /^(?<indent>\s*)(class|module) /
23
+ @title = "Classes missing coverage"
24
+ when :method
25
+ @block_start_regex = /^(?<indent>\s*)(def) /
26
+ @title = "Methods missing coverage"
27
+ when :configure
28
+ @block_start_regex = /^(?<indent>\s*)(configure) /
29
+ @title = "Configure methods missing coverage"
30
+ end
31
+ end
32
+
33
+ def generate(files)
34
+ @report = {
35
+ :type => {
36
+ :main => :file_report,
37
+ :subtype => @report_type
38
+ },
39
+ :title => @title,
40
+ :items => ItemMap.new
41
+ }
42
+
43
+ files.each do |file|
44
+ @report[:items][file] = SimpleCov::SourceFile::LineList.new
45
+
46
+ file.lines.each_with_index do |line, line_number|
47
+ line = file.lines[line_number]
48
+ method_started = @block_start_regex.match(line.source)
49
+ if method_started && line.missed?
50
+ @report[:items][file] << line
51
+ next
52
+ end
53
+
54
+ next_line = file.lines[line_number + 1]
55
+ missed_next_line = method_started && next_line.missed?
56
+ if method_started && missed_next_line
57
+ @report[:items][file] << line
58
+ next
59
+ end
60
+
61
+ method_ends_on_same_line = /\bend\s*$/.match(line.source)
62
+ if method_started && method_ends_on_same_line
63
+ # line.source += " *"
64
+ next
65
+ end
66
+
67
+ next_line = file.lines[line_number + 1]
68
+ next_line_excluded = method_started && next_line.never?
69
+ if method_started && next_line_excluded
70
+ method_start_line = line
71
+ begin
72
+ line_number += 1
73
+ line = file.lines[line_number]
74
+ method_ended = BLOCK_END_REGEX.match(line.source)
75
+ method_ended = method_ended && method_started["indent"].length >= method_ended["indent"].length
76
+ next_line_included = !line.never?
77
+ end until method_ended || next_line_included
78
+
79
+ missed_next_line = line.missed?
80
+ if missed_next_line
81
+ # line.source += " **"
82
+ @report[:items][file] << method_start_line
83
+ end
84
+ end
85
+ end # file.lines.each
86
+
87
+ @report[:items].delete(file) if @report[:items][file].empty?
88
+ end # result.files.each
89
+
90
+ @report
91
+ end # generate(files)
92
+
93
+ end # class FileReport
94
+
95
+ end # module SimpleCov
96
+
97
+ SimpleCov::Report.register(:file_report, SimpleCov::FileReport)
@@ -0,0 +1,5 @@
1
+ module Simplecov
2
+ module Reports
3
+ VERSION = "0.0.4.ooyala"
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ require "ooyala-grit"
2
+ require "simplecov"
3
+
4
+ module SimpleCov
5
+ class SourceFile
6
+ class Line
7
+ # Author of the line
8
+ attr_accessor :author
9
+ # Authored date
10
+ attr_accessor :date
11
+ end
12
+ end
13
+
14
+ SimpleCov::SourceFile.add_line_enhancer(lambda do |lines, filename|
15
+ author_info = []
16
+ root_dir = Grit::Git.new(Dir.pwd).native(:rev_parse, {:base => false}, "--show-toplevel").chomp
17
+ repo = Grit::Repo.new(root_dir)
18
+ begin
19
+ blame = repo.blame(File.realdirpath(filename), nil, {:base => false})
20
+ blame.lines.each_with_index do |blame_line, line_number|
21
+ author_info << { :author => blame_line.commit.author.name, :date => blame_line.commit.date }
22
+ end
23
+ rescue Exception => e
24
+ puts "`git blame` on \'#{filename}\' encountered exception: #{e.message}. Skipping adding author info."
25
+ end
26
+
27
+ # Initialize lines
28
+ lines.each_with_index do |line, i|
29
+ line_author_info = i < author_info.length ? author_info[i] : nil
30
+ if !line_author_info.nil?
31
+ line.author = line_author_info[:author]
32
+ line.date = line_author_info[:date]
33
+ end
34
+ end
35
+ end
36
+ )
37
+
38
+ end
39
+
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simplecov/reports/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simplecov-reports"
8
+ spec.version = Simplecov::Reports::VERSION
9
+ spec.authors = ["Rajesh Konda"]
10
+ spec.email = ["rkonda@ooyala.com"]
11
+ spec.description = "Contains code that enhances simplecov, and simplecov-html gems with FileReport and AuthorReport"
12
+ spec.summary = "Reports added to simplecov and simplecov-html: FileReport and AuthorReport"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry-nav"
24
+ spec.add_development_dependency "shoulda"
25
+
26
+ spec.add_dependency "ooyala-grit"
27
+ spec.add_dependency "simplecov", "0.9.3.ooyala"
28
+ spec.add_dependency "simplecov-html", "0.7.6.ooyala"
29
+ end
@@ -0,0 +1,23 @@
1
+ # author=="AuthorTesterOne"
2
+ # (3/10) 30% coverage
3
+ if COVERAGE == "cover"
4
+ line = "Author-1 1"
5
+ line = "Author-1 2"
6
+ else
7
+ line = "Author-1 3"
8
+ line = "Author-1 4"
9
+ line = "Author-1 5"
10
+ line = "Author-1 6"
11
+ line = "Author-1 7"
12
+ line = "Author-1 8"
13
+ line = "Author-1 9"
14
+ end
15
+
16
+ # author=="AuthorTesterTwo"
17
+ # (1/4) 25% coverage
18
+ if COVERAGE == "cover"
19
+ else
20
+ line = "Author-2 1"
21
+ line = "Author-2 2"
22
+ line = "Author-2 3"
23
+ end
@@ -0,0 +1,26 @@
1
+ # author=="AuthorTesterOne"
2
+ # (1/10) 10% coverage
3
+ if COVERAGE == "cover"
4
+ else
5
+ line = "Author-1 1"
6
+ line = "Author-1 2"
7
+ line = "Author-1 3"
8
+ line = "Author-1 4"
9
+ line = "Author-1 5"
10
+ line = "Author-1 6"
11
+ line = "Author-1 7"
12
+ line = "Author-1 8"
13
+ line = "Author-1 9"
14
+ end
15
+
16
+ # author=="AuthorTesterThree"
17
+ # (4/4) 100% coverage
18
+ if COVERAGE == "cover"
19
+ line = "Author-3 1"
20
+ line = "Author-3 2"
21
+ line = "Author-3 3"
22
+ else
23
+ end
24
+
25
+ # author=="AuthorTesterFour"
26
+ # (0/0) coverage is NA
@@ -0,0 +1,264 @@
1
+ # author=="Rajesh Konda"
2
+ # (10/100) 10% coverage
3
+ if COVERAGE == "cover"
4
+ line = "Rajesh 1"
5
+ line = "Rajesh 2"
6
+ line = "Rajesh 3"
7
+ line = "Rajesh 4"
8
+ line = "Rajesh 5"
9
+ line = "Rajesh 6"
10
+ line = "Rajesh 7"
11
+ line = "Rajesh 8"
12
+ line = "Rajesh 9"
13
+ else
14
+ line = "Rajesh 10"
15
+ line = "Rajesh 11"
16
+ line = "Rajesh 12"
17
+ line = "Rajesh 13"
18
+ line = "Rajesh 14"
19
+ line = "Rajesh 15"
20
+ line = "Rajesh 16"
21
+ line = "Rajesh 17"
22
+ line = "Rajesh 18"
23
+ line = "Rajesh 19"
24
+ line = "Rajesh 20"
25
+ line = "Rajesh 21"
26
+ line = "Rajesh 22"
27
+ line = "Rajesh 23"
28
+ line = "Rajesh 24"
29
+ line = "Rajesh 25"
30
+ line = "Rajesh 26"
31
+ line = "Rajesh 27"
32
+ line = "Rajesh 28"
33
+ line = "Rajesh 29"
34
+ line = "Rajesh 30"
35
+ line = "Rajesh 31"
36
+ line = "Rajesh 32"
37
+ line = "Rajesh 33"
38
+ line = "Rajesh 34"
39
+ line = "Rajesh 35"
40
+ line = "Rajesh 36"
41
+ line = "Rajesh 37"
42
+ line = "Rajesh 38"
43
+ line = "Rajesh 39"
44
+ line = "Rajesh 40"
45
+ line = "Rajesh 41"
46
+ line = "Rajesh 42"
47
+ line = "Rajesh 43"
48
+ line = "Rajesh 44"
49
+ line = "Rajesh 45"
50
+ line = "Rajesh 46"
51
+ line = "Rajesh 47"
52
+ line = "Rajesh 48"
53
+ line = "Rajesh 49"
54
+ line = "Rajesh 50"
55
+ line = "Rajesh 51"
56
+ line = "Rajesh 52"
57
+ line = "Rajesh 53"
58
+ line = "Rajesh 54"
59
+ line = "Rajesh 55"
60
+ line = "Rajesh 56"
61
+ line = "Rajesh 57"
62
+ line = "Rajesh 58"
63
+ line = "Rajesh 59"
64
+ line = "Rajesh 60"
65
+ line = "Rajesh 61"
66
+ line = "Rajesh 62"
67
+ line = "Rajesh 63"
68
+ line = "Rajesh 64"
69
+ line = "Rajesh 65"
70
+ line = "Rajesh 66"
71
+ line = "Rajesh 67"
72
+ line = "Rajesh 68"
73
+ line = "Rajesh 69"
74
+ line = "Rajesh 70"
75
+ line = "Rajesh 71"
76
+ line = "Rajesh 72"
77
+ line = "Rajesh 73"
78
+ line = "Rajesh 74"
79
+ line = "Rajesh 75"
80
+ line = "Rajesh 76"
81
+ line = "Rajesh 77"
82
+ line = "Rajesh 78"
83
+ line = "Rajesh 79"
84
+ line = "Rajesh 80"
85
+ line = "Rajesh 81"
86
+ line = "Rajesh 82"
87
+ line = "Rajesh 83"
88
+ line = "Rajesh 84"
89
+ line = "Rajesh 85"
90
+ line = "Rajesh 86"
91
+ line = "Rajesh 87"
92
+ line = "Rajesh 88"
93
+ line = "Rajesh 89"
94
+ line = "Rajesh 90"
95
+ line = "Rajesh 91"
96
+ line = "Rajesh 92"
97
+ line = "Rajesh 93"
98
+ line = "Rajesh 94"
99
+ line = "Rajesh 95"
100
+ line = "Rajesh 96"
101
+ line = "Rajesh 97"
102
+ line = "Rajesh 98"
103
+ line = "Rajesh 99"
104
+ end
105
+
106
+ # author=="AuthorTesterOne"
107
+ # (14/70) 20% coverage
108
+ if COVERAGE == "cover"
109
+ line = "Author-1 101"
110
+ line = "Author-1 102"
111
+ line = "Author-1 103"
112
+ line = "Author-1 104"
113
+ line = "Author-1 105"
114
+ line = "Author-1 106"
115
+ line = "Author-1 107"
116
+ line = "Author-1 108"
117
+ line = "Author-1 109"
118
+ line = "Author-1 110"
119
+ line = "Author-1 111"
120
+ line = "Author-1 112"
121
+ line = "Author-1 113"
122
+ else
123
+ line = "Author-1 114"
124
+ line = "Author-1 115"
125
+ line = "Author-1 116"
126
+ line = "Author-1 117"
127
+ line = "Author-1 118"
128
+ line = "Author-1 119"
129
+ line = "Author-1 120"
130
+ line = "Author-1 121"
131
+ line = "Author-1 122"
132
+ line = "Author-1 123"
133
+ line = "Author-1 124"
134
+ line = "Author-1 125"
135
+ line = "Author-1 126"
136
+ line = "Author-1 127"
137
+ line = "Author-1 128"
138
+ line = "Author-1 129"
139
+ line = "Author-1 130"
140
+ line = "Author-1 131"
141
+ line = "Author-1 132"
142
+ line = "Author-1 133"
143
+ line = "Author-1 134"
144
+ line = "Author-1 135"
145
+ line = "Author-1 136"
146
+ line = "Author-1 137"
147
+ line = "Author-1 138"
148
+ line = "Author-1 139"
149
+ line = "Author-1 140"
150
+ line = "Author-1 141"
151
+ line = "Author-1 142"
152
+ line = "Author-1 143"
153
+ line = "Author-1 144"
154
+ line = "Author-1 145"
155
+ line = "Author-1 146"
156
+ line = "Author-1 147"
157
+ line = "Author-1 148"
158
+ line = "Author-1 149"
159
+ line = "Author-1 150"
160
+ line = "Author-1 151"
161
+ line = "Author-1 152"
162
+ line = "Author-1 153"
163
+ line = "Author-1 154"
164
+ line = "Author-1 155"
165
+ line = "Author-1 156"
166
+ line = "Author-1 157"
167
+ line = "Author-1 158"
168
+ line = "Author-1 159"
169
+ line = "Author-1 160"
170
+ line = "Author-1 161"
171
+ line = "Author-1 162"
172
+ line = "Author-1 163"
173
+ line = "Author-1 164"
174
+ line = "Author-1 165"
175
+ line = "Author-1 166"
176
+ line = "Author-1 167"
177
+ line = "Author-1 168"
178
+ line = "Author-1 169"
179
+ end
180
+
181
+ # author=="AuthorTesterTwo"
182
+ # (9/30) 30% coverage
183
+ if COVERAGE == "cover"
184
+ line = "Author-2 201"
185
+ line = "Author-2 202"
186
+ line = "Author-2 203"
187
+ line = "Author-2 204"
188
+ line = "Author-2 205"
189
+ line = "Author-2 206"
190
+ line = "Author-2 207"
191
+ line = "Author-2 208"
192
+ else
193
+ line = "Author-2 209"
194
+ line = "Author-2 210"
195
+ line = "Author-2 211"
196
+ line = "Author-2 212"
197
+ line = "Author-2 213"
198
+ line = "Author-2 214"
199
+ line = "Author-2 215"
200
+ line = "Author-2 216"
201
+ line = "Author-2 217"
202
+ line = "Author-2 218"
203
+ line = "Author-2 219"
204
+ line = "Author-2 220"
205
+ line = "Author-2 221"
206
+ line = "Author-2 222"
207
+ line = "Author-2 223"
208
+ line = "Author-2 224"
209
+ line = "Author-2 225"
210
+ line = "Author-2 226"
211
+ line = "Author-2 227"
212
+ line = "Author-2 228"
213
+ line = "Author-2 229"
214
+ end
215
+
216
+ # author=="AuthorTesterThree"
217
+ # (12/30) 40% coverage
218
+ if COVERAGE == "cover"
219
+ line = "Author-3 301"
220
+ line = "Author-3 302"
221
+ line = "Author-3 303"
222
+ line = "Author-3 304"
223
+ line = "Author-3 305"
224
+ line = "Author-3 306"
225
+ line = "Author-3 307"
226
+ line = "Author-3 308"
227
+ line = "Author-3 309"
228
+ line = "Author-3 310"
229
+ line = "Author-3 311"
230
+ else
231
+ line = "Author-3 312"
232
+ line = "Author-3 313"
233
+ line = "Author-3 314"
234
+ line = "Author-3 315"
235
+ line = "Author-3 316"
236
+ line = "Author-3 317"
237
+ line = "Author-3 318"
238
+ line = "Author-3 319"
239
+ line = "Author-3 320"
240
+ line = "Author-3 321"
241
+ line = "Author-3 322"
242
+ line = "Author-3 323"
243
+ line = "Author-3 324"
244
+ line = "Author-3 325"
245
+ line = "Author-3 326"
246
+ line = "Author-3 327"
247
+ line = "Author-3 328"
248
+ line = "Author-3 329"
249
+ end
250
+
251
+ # author=="AuthorTesterFour"
252
+ # (5/10) 50% coverage
253
+ if COVERAGE == "cover"
254
+ line = "Author-4 401"
255
+ line = "Author-4 402"
256
+ line = "Author-4 403"
257
+ line = "Author-4 404"
258
+ else
259
+ line = "Author-4 405"
260
+ line = "Author-4 406"
261
+ line = "Author-4 407"
262
+ line = "Author-4 408"
263
+ line = "Author-4 409"
264
+ end