annotation
in the file fileName
. This will
37 | * create an entry in metrics
for fileName
if one does not already
38 | * exist.
39 | *
40 | * @param fileName the filename from the output of Rails notes.
41 | * @param annotation the RailsNotesMetrics
value associated with the annotation
42 | * in the report.
43 | */
44 | public void addAnnotationFor(String fileName, RailsNotesMetrics annotation) {
45 | if (!sortedLabels.contains(fileName)) {
46 | sortedLabels.add(fileName);
47 | }
48 |
49 | // Create the map if it doesn't already exist, seed each annotation with a count of 0.
50 | if (!metrics.containsKey(fileName)) {
51 | Mapmetrics
.
65 | *
66 | * @return A Map
to insert into metrics
with each annotation and a
67 | * total count.
68 | */
69 | public Map${header} | 20 ||
${metric.key} | 27 |${values.value} | 29 |
${it.results.output}38 |
${header} | 29 ||
${metric.key} | 36 |${values.value} | 38 |
9 | Tracking and trending code coverage works best when like is compared with like. In this regard it is 10 | best to only track builds when all unit tests are passing. 11 |
12 |13 | This plugin will not report code coverage until there is at least one stable build. 14 |
15 |Name | 19 |Total lines | 20 |Lines of code | 21 |Total coverage | 22 |Code coverage | 23 |
TOTAL | 28 |${it.results.totalLines} | 29 |${it.results.codeLines} | 30 | 31 |||
${file.name} | 42 |${file.totalLines} | 43 |${file.codeLines} | 44 | 45 |
9 | Tracking and trending code coverage works best when like is compared with like. In this regard it is 10 | best to only track builds when all unit tests are passing. 11 |
12 |13 | This plugin will not report code coverage until there is at least one stable build. 14 |
15 |${inst.metric.name} | 24 | 25 |
26 | ![]() |
29 |
30 | |
32 |
33 | ![]() |
36 |
37 | |
39 |
40 | ![]() |
43 |
44 | |
46 |
---|
Name | 15 |Total lines | 16 |Lines of code | 17 |Total coverage | 18 |Code coverage | 19 |
${it.result.name} | 24 |${it.result.totalLines} | 25 |${it.result.codeLines} | 26 | 27 |
${attrs.coverage} | 9 |
10 |
|
17 |
8 | Tracking and trending code coverage works best when like is compared with like. In this regard it is 9 | best to only track builds when all unit tests are passing. 10 |
11 |12 | This plugin will not report code coverage until there is at least one stable build. 13 |
14 |", ""); 38 | } 39 | 40 | private void assertSourceIsWellFormed(String href, String start, String end) throws Exception { 41 | File root = new File(this.getClass().getResource(href).toURI()).getParentFile(); 42 | RcovParser parser = new RcovParser(root); 43 | 44 | String source = parser.parseSource(href); 45 | assertNotNull(source); 46 | assertTrue(source.startsWith(start)); 47 | assertTrue(source.endsWith(end)); 48 | } 49 | 50 | private void assertReportIsComplete(File root, InputStream input) throws Exception { 51 | RcovParser parser = new RcovParser(root); 52 | RcovResult result = parser.parse(input); 53 | 54 | assertNotNull(result); 55 | 56 | assertTrue(result.getFiles().size() > 0); 57 | 58 | assertIsAValidNode(result.getTotalCoverage()); 59 | assertIsAValidNode(result.getTotalLines()); 60 | assertIsAValidNode(result.getCodeCoverage()); 61 | assertIsAValidNode(result.getCodeLines()); 62 | 63 | //Check first file 64 | RcovFileResult fileResult = result.getFiles().iterator().next(); 65 | 66 | assertIsAValidNode(fileResult.getTotalCoverage()); 67 | assertIsAValidNode(fileResult.getTotalLines()); 68 | assertIsAValidNode(fileResult.getCodeCoverage()); 69 | assertIsAValidNode(fileResult.getCodeLines()); 70 | } 71 | 72 | private void assertIsAValidNode(String element) { 73 | assertTrue(element.matches("[0-9%.]+")); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/hudson/plugins/rubyMetrics/rcov/model/RcovFileDetailTest.java: -------------------------------------------------------------------------------- 1 | package hudson.plugins.rubyMetrics.rcov.model; 2 | 3 | import hudson.FilePath; 4 | import hudson.Launcher; 5 | import hudson.model.AbstractBuild; 6 | import hudson.model.BuildListener; 7 | import hudson.model.FreeStyleBuild; 8 | import hudson.model.FreeStyleProject; 9 | import hudson.plugins.rubyMetrics.rcov.RcovBuildAction; 10 | import hudson.plugins.rubyMetrics.rcov.RcovPublisher; 11 | import org.junit.Rule; 12 | import org.junit.Test; 13 | import org.jvnet.hudson.test.JenkinsRule; 14 | import org.jvnet.hudson.test.TestBuilder; 15 | 16 | import java.io.File; 17 | import java.io.IOException; 18 | import java.util.Collections; 19 | 20 | import static org.junit.Assert.assertNotNull; 21 | import static org.junit.Assert.assertThat; 22 | import static org.junit.matchers.JUnitMatchers.containsString; 23 | 24 | public class RcovFileDetailTest { 25 | private static final String COVERAGE_DIR = "coverage/rcov"; 26 | 27 | @Rule 28 | public final JenkinsRule j = new JenkinsRule(); 29 | 30 | @Test 31 | public void testLoadSourceCode() throws Exception { 32 | File resourceDir = new File(this.getClass().getResource("index.html").toURI()).getParentFile(); 33 | final FilePath resourcePath = new FilePath(resourceDir); 34 | 35 | FreeStyleProject project = j.createFreeStyleProject(); 36 | 37 | // Builder to copy the coverage fixture files into the workspace 38 | project.getBuildersList().add(new TestBuilder() { 39 | public boolean perform(AbstractBuild, ?> build, Launcher launcher, 40 | BuildListener listener) throws InterruptedException, IOException { 41 | 42 | FilePath rcovDir = build.getWorkspace().child(COVERAGE_DIR); 43 | rcovDir.mkdirs(); 44 | resourcePath.copyRecursiveTo("*.html", rcovDir); 45 | return true; 46 | } 47 | }); 48 | 49 | // Add the rcov publisher 50 | RcovPublisher publisher = new RcovPublisher(COVERAGE_DIR); 51 | publisher.setTargets(Collections.
Name | 42 |Total Lines | 43 |Lines of Code | 44 |Total Coverage | 45 |Code Coverage | 46 |
---|---|---|---|---|
TOTAL | 51 |910 | 52 |702 | 53 |64.62%
54 |
55 |
56 |
57 | |
58 | 56.27%
59 |
60 |
61 |
62 | |
63 |
lib/octopi.rb | 69 |235 | 70 |198 | 71 |46.81%
72 |
73 |
74 |
75 | |
76 | 40.40%
77 |
78 |
79 |
80 | |
81 |
lib/octopi/base.rb | 85 |111 | 86 |94 | 87 |89.19%
88 |
89 |
90 |
91 | |
92 | 87.23%
93 |
94 |
95 |
96 | |
97 |
lib/octopi/blob.rb | 101 |21 | 102 |19 | 103 |38.10%
104 |
105 |
106 |
107 | |
108 | 31.58%
109 |
110 |
111 |
112 | |
113 |
lib/octopi/branch.rb | 117 |18 | 118 |16 | 119 |44.44%
120 |
121 |
122 |
123 | |
124 | 37.50%
125 |
126 |
127 |
128 | |
129 |
lib/octopi/commit.rb | 133 |65 | 134 |44 | 135 |63.08%
136 |
137 |
138 |
139 | |
140 | 47.73%
141 |
142 |
143 |
144 | |
145 |
lib/octopi/error.rb | 149 |23 | 150 |20 | 151 |47.83%
152 |
153 |
154 |
155 | |
156 | 40.00%
157 |
158 |
159 |
160 | |
161 |
lib/octopi/file_object.rb | 165 |15 | 166 |13 | 167 |53.33%
168 |
169 |
170 |
171 | |
172 | 46.15%
173 |
174 |
175 |
176 | |
177 |
lib/octopi/issue.rb | 181 |102 | 182 |70 | 183 |82.35%
184 |
185 |
186 |
187 | |
188 | 74.29%
189 |
190 |
191 |
192 | |
193 |
lib/octopi/key.rb | 197 |18 | 198 |15 | 199 |50.00%
200 |
201 |
202 |
203 | |
204 | 40.00%
205 |
206 |
207 |
208 | |
209 |
lib/octopi/repository.rb | 213 |111 | 214 |77 | 215 |63.06%
216 |
217 |
218 |
219 | |
220 | 50.65%
221 |
222 |
223 |
224 | |
225 |
lib/octopi/resource.rb | 229 |75 | 230 |62 | 231 |98.67%
232 |
233 |
234 |
235 | |
236 | 98.39%
237 |
238 |
239 |
240 | |
241 |
lib/octopi/tag.rb | 245 |17 | 246 |15 | 247 |47.06%
248 |
249 |
250 |
251 | |
252 | 40.00%
253 |
254 |
255 |
256 | |
257 |
lib/octopi/user.rb | 261 |99 | 262 |59 | 263 |58.59%
264 |
265 |
266 |
267 | |
268 | 37.29%
269 |
270 |
271 |
272 | |
273 |
Generated on Fri Sep 11 12:36:42 +0200 2009 with rcov 0.9.0
280 | 281 | 296 | 297 | 298 | 299 | -------------------------------------------------------------------------------- /src/test/resources/hudson/plugins/rubyMetrics/rcov/lib-trinidad-core_ext_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |Name | 22 |Total Lines | 23 |Lines of Code | 24 |Total Coverage | 25 |Code Coverage | 26 |
---|---|---|---|---|
lib/trinidad/core_ext.rb | 31 |33 | 32 |22 | 33 |30.30%
34 |
35 |
36 |
37 | |
38 | 13.64%
39 |
40 |
41 |
42 | |
43 |
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 Hash.class_eval do |
61 |
2 # Merges self with another hash, recursively. |
67 |
3 # |
73 |
4 # This code was lovingly stolen from some random gem: |
79 |
5 # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html |
85 |
6 # |
91 |
7 # Thanks to whoever made it. |
97 |
8 def deep_merge(hash) |
103 |
9 target = dup |
109 |
10 |
115 |
11 hash.keys.each do |key| |
121 |
12 if hash[key].is_a? Hash and self[key].is_a? Hash |
127 |
13 target[key] = target[key].deep_merge(hash[key]) |
133 |
14 next |
139 |
15 end |
145 |
16 |
151 |
17 target[key] = hash[key] |
157 |
18 end |
163 |
19 |
169 |
20 target |
175 |
21 end |
181 |
22 |
187 |
23 def deep_merge!(second) |
193 |
24 second.each_pair do |k,v| |
199 |
25 if self[k].is_a?(Hash) and second[k].is_a?(Hash) |
205 |
26 self[k].deep_merge!(second[k]) |
211 |
27 else |
217 |
28 self[k] = second[k] |
223 |
29 end |
229 |
30 end |
235 |
31 end |
241 |
32 |
247 |
33 end |
253 |
Generated on Wed Dec 30 22:56:48 +0100 2009 with rcov 0.9.7.1
259 | 260 | 261 | 262 | -------------------------------------------------------------------------------- /src/test/resources/hudson/plugins/rubyMetrics/rcov/model/build.xml: -------------------------------------------------------------------------------- 1 | 2 |Name | 40 |Total Lines | 41 |Lines of Code | 42 |Total Coverage | 43 |Code Coverage | 44 |
---|---|---|---|---|
TOTAL | 49 |32 | 50 |19 | 51 |100.00%
52 |
53 |
54 |
55 | |
56 | 100.00%
57 |
58 |
59 |
60 | |
61 |
lib/app.rb | 67 |5 | 68 |3 | 69 |100.00%
70 |
71 |
72 |
73 | |
74 | 100.00%
75 |
76 |
77 |
78 | |
79 |
lib/app/service.rb | 83 |11 | 84 |6 | 85 |100.00%
86 |
87 |
88 |
89 | |
90 | 100.00%
91 |
92 |
93 |
94 | |
95 |
lib/app/version.rb | 99 |3 | 100 |2 | 101 |100.00%
102 |
103 |
104 |
105 | |
106 | 100.00%
107 |
108 |
109 |
110 | |
111 |
spec/app_spec.rb | 115 |13 | 116 |8 | 117 |100.00%
118 |
119 |
120 |
121 | |
122 | 100.00%
123 |
124 |
125 |
126 | |
127 |
Generated on 2014-02-05 12:55:46 -0800 with SimpleCov-RCov 0.2.3
134 | 135 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /src/test/resources/hudson/plugins/rubyMetrics/rcov/model/lib-app-service_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |Name | 19 |Total Lines | 20 |Lines of Code | 21 |Total Coverage | 22 |Code Coverage | 23 |
---|---|---|---|---|
lib/app/service.rb | 28 |11 | 29 |6 | 30 |100.00%
31 |
32 |
33 |
34 | |
35 | 100.00%
36 |
37 |
38 |
39 | |
40 |
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
2 module App |
55 |
3 class Service |
58 |
4 def do_it |
61 |
5 "Doing it!" |
64 |
6 end |
67 |
7 |
70 |
8 def fail |
73 |
9 raise "Fail!" |
76 |
10 end |
79 |
11 end |
82 |
12 end |
85 |
Generated on 2014-02-05 12:55:46 -0800 with SimpleCov-RCov 0.2.3
90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /src/test/resources/hudson/plugins/rubyMetrics/rcov/model/lib-app-version_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |Name | 19 |Total Lines | 20 |Lines of Code | 21 |Total Coverage | 22 |Code Coverage | 23 |
---|---|---|---|---|
lib/app/version.rb | 28 |3 | 29 |2 | 30 |100.00%
31 |
32 |
33 |
34 | |
35 | 100.00%
36 |
37 |
38 |
39 | |
40 |
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
2 module App |
55 |
3 VERSION = '1.0.0' |
58 |
4 end |
61 |
Generated on 2014-02-05 12:55:46 -0800 with SimpleCov-RCov 0.2.3
66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/test/resources/hudson/plugins/rubyMetrics/rcov/model/lib-app_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |Name | 19 |Total Lines | 20 |Lines of Code | 21 |Total Coverage | 22 |Code Coverage | 23 |
---|---|---|---|---|
lib/app.rb | 28 |5 | 29 |3 | 30 |100.00%
31 |
32 |
33 |
34 | |
35 | 100.00%
36 |
37 |
38 |
39 | |
40 |
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
2 require 'app/version' |
55 |
3 require 'app/service' |
58 |
4 |
61 |
5 module App |
64 |
6 end |
67 |
Generated on 2014-02-05 12:55:46 -0800 with SimpleCov-RCov 0.2.3
72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/test/resources/hudson/plugins/rubyMetrics/rcov/model/spec-app_spec_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |Name | 19 |Total Lines | 20 |Lines of Code | 21 |Total Coverage | 22 |Code Coverage | 23 |
---|---|---|---|---|
spec/app_spec.rb | 28 |13 | 29 |8 | 30 |100.00%
31 |
32 |
33 |
34 | |
35 | 100.00%
36 |
37 |
38 |
39 | |
40 |
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
2 require 'app' |
55 |
3 |
58 |
4 describe App::Service do |
61 |
5 it "returns from do_it" do |
64 |
6 service = App::Service.new |
67 |
7 service.do_it.should_not be_nil |
70 |
8 end |
73 |
9 |
76 |
10 it "raises from fail" do |
79 |
11 service = App::Service.new |
82 |
12 expect { service.fail }.to raise_error |
85 |
13 end |
88 |
14 end |
91 |
Generated on 2014-02-05 12:55:46 -0800 with SimpleCov-RCov 0.2.3
96 | 97 | 98 | 99 | --------------------------------------------------------------------------------