firespring_dev_commands 2.1.21.pre.alpha.7 → 2.1.21.pre.alpha.8
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82b69d61d6649aaa851e8000d68b651193d265b29be96318e5bbbf0383a901e7
|
4
|
+
data.tar.gz: 880ff091de3b0318a4c6b2838494ba4d68c47a325457d98a88008acee6d2bcf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5dfffdc56f103e23c0a00331003a1499a9cb9444a732a71355143b1e34682ee0d9a07215c096b29b42cbbd46d24d6ac43cc9ac890d6e4f2042fe31f463f8833
|
7
|
+
data.tar.gz: f08ea0a75721208a727934db0c3bd1b896b28f5f59e3c14efbd7a5468ac792df49543e175e73ad430cfcad8694318e1607d167ca06adccc17c91be9ac3456378
|
@@ -3,13 +3,14 @@ module Dev
|
|
3
3
|
module Coverage
|
4
4
|
# Class for checking code coverage using cobertura
|
5
5
|
class Cobertura
|
6
|
-
attr_reader :local_filename, :container_filename, :filename, :threshold
|
6
|
+
attr_reader :local_filename, :container_filename, :filename, :threshold, :exclude
|
7
7
|
|
8
|
-
def initialize(filename: File.join('coverage', 'cobertura.xml'), threshold: nil, container_path: nil, local_path: nil)
|
8
|
+
def initialize(filename: File.join('coverage', 'cobertura.xml'), threshold: nil, container_path: nil, local_path: nil, exclude: nil)
|
9
9
|
@filename = filename
|
10
10
|
@local_filename = File.join(local_path || '.', @filename)
|
11
11
|
@container_filename = File.join(container_path || '.', @filename)
|
12
12
|
@threshold = threshold
|
13
|
+
@exclude = exclude || []
|
13
14
|
end
|
14
15
|
|
15
16
|
# Remove any previous versions of the local file that will be output
|
@@ -22,7 +23,7 @@ module Dev
|
|
22
23
|
%W(--coverage-cobertura #{container_filename})
|
23
24
|
end
|
24
25
|
|
25
|
-
# Parse the cobertura file
|
26
|
+
# Parse the cobertura file and check the lines missed against the desired threshold
|
26
27
|
def check(application: nil)
|
27
28
|
# If an application has been specified and the file does not exist locally, attempt to copy it back from the docker container
|
28
29
|
if application && !File.exist?(local_filename)
|
@@ -30,26 +31,47 @@ module Dev
|
|
30
31
|
Dev::Docker.new.copy_from_container(container, container_filename, local_filename, required: true)
|
31
32
|
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
34
|
+
report = Ox.load(File.read(local_filename))
|
35
|
+
total_missed = report.coverage.locate('packages/package').sum { |package| parse_package_missed(package) }
|
36
|
+
puts "Lines missing coverage was #{total_missed}"
|
37
|
+
puts "Configured threshold was #{threshold}" if threshold
|
38
|
+
raise 'Code coverage not met' if threshold && total_missed > threshold
|
39
|
+
end
|
40
|
+
|
41
|
+
# Go through the package and add up all of the lines that were missed
|
42
|
+
# Ignore if the file was in the exlude list
|
43
|
+
private def parse_package_missed(package)
|
44
|
+
filename = package.attributes[:name]
|
45
|
+
return if exclude.any? { |it| it.match(filename) }
|
46
|
+
|
47
|
+
missed = 0
|
48
|
+
lines_processed = Set.new
|
49
|
+
package.locate('classes/class/lines/line').each do |line|
|
50
|
+
# Don't count lines multiple times
|
51
|
+
line_number = line.attributes[:number]
|
52
|
+
next if lines_processed.include?(line_number)
|
53
|
+
|
54
|
+
lines_processed << line_number
|
55
|
+
missed += 1 unless line.attributes[:hits].to_i.positive?
|
48
56
|
end
|
57
|
+
total = lines_processed.length
|
58
|
+
sanity_check_coverage_against_cobertura_values(package, missed, total)
|
59
|
+
missed
|
60
|
+
end
|
49
61
|
|
50
|
-
|
51
|
-
|
52
|
-
|
62
|
+
# Calculate the coverage percent based off the numbers we got and compare to the
|
63
|
+
# value cobertura reported. This is meant as a sanity check that we are reading the data correctly
|
64
|
+
private def sanity_check_coverage_against_cobertura_values(package, missed, total)
|
65
|
+
line_rate = package.attributes[:'line-rate']
|
66
|
+
cobertura_reported_coverage = line_rate.to_f
|
67
|
+
cobertura_reported_precision = line_rate.split('.').last.length
|
68
|
+
|
69
|
+
file_coverage = 0.0
|
70
|
+
file_coverage = ((total - missed).to_f / total).round(cobertura_reported_precision) if total.positive?
|
71
|
+
return if file_coverage == cobertura_reported_coverage
|
72
|
+
|
73
|
+
filename = package.attributes[:name]
|
74
|
+
puts "WARNINNG: #{filename} coverage (#{file_coverage}) differed from what cobertura reported (#{cobertura_reported_coverage})".light_yellow
|
53
75
|
end
|
54
76
|
end
|
55
77
|
end
|