firespring_dev_commands 2.1.21.pre.alpha.7 → 2.1.21.pre.alpha.8

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
  SHA256:
3
- metadata.gz: 8854ab66747e26c22780c4e6756df86dac09bc5a8029fae51f1382d29d18c27f
4
- data.tar.gz: ca3ddd354a8faddb180d827891886ce78483accb7e7f1e2e5b5b9d6bcc9d36f7
3
+ metadata.gz: 82b69d61d6649aaa851e8000d68b651193d265b29be96318e5bbbf0383a901e7
4
+ data.tar.gz: 880ff091de3b0318a4c6b2838494ba4d68c47a325457d98a88008acee6d2bcf0
5
5
  SHA512:
6
- metadata.gz: 4aace4ef89ab6ec98008184ffb58d71febc920bcc85195a3fe2fa645a4109f8523348cdfae5e281a731d6ce6ddac3769a101800ee7b6e63ad31f4efcfa2f84c4
7
- data.tar.gz: c700fd928018dc384757fddeae412eb4990323b94b47a16026736738d43e4a8ff12202b15014ebd0b92d30f5705dcffeab439a78e61ea711e0074ecff22d6cec
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 as a hash and check the total coverage against the desired threshold
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
- # Load the file from disk and parse with ox
34
- report = Ox.load(File.read(local_filename), mode: :hash)
35
- _, _, files = report[:coverage]
36
-
37
- covered = missed = 0
38
- files.dig(:packages, :package)&.each do |_attrs, packages|
39
- _, _, lines = *packages&.dig(:classes, :class)
40
- lines&.dig(:lines, :line)&.each do |it|
41
- it = it&.first if it.is_a?(Array)
42
- if it&.dig(:hits).to_i.positive?
43
- covered += 1
44
- else
45
- missed += 1
46
- end
47
- end
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
- puts "Lines missing coverage was #{missed}"
51
- puts "Configured threshold was #{threshold}" if threshold
52
- raise 'Code coverage not met' if threshold && missed > threshold
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
@@ -6,6 +6,6 @@ module Dev
6
6
  # Use 'v.v.v.pre.alpha.v' for pre-release vesions
7
7
  # Use 'v.v.v.beta.v for beta versions
8
8
  # Use semantic versioning for any releases (https://semver.org/)
9
- VERSION = '2.1.21.pre.alpha.7'.freeze
9
+ VERSION = '2.1.21.pre.alpha.8'.freeze
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firespring_dev_commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.21.pre.alpha.7
4
+ version: 2.1.21.pre.alpha.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firespring