Sha256: 054cc220eefd68e741abddc709b434e7af1397c6188e119eda29a18ec9a9484d

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023, by Samuel Williams.

def initialize(context)
	super
	
	require_relative '../../lib/covered/config'
end

# Load the current coverage policy.
# Defaults to the default coverage path if no paths are specified.
# @parameter paths [Array(String)] The coverage database paths.
def current(paths: nil)
	policy = Covered::Policy.new
	
	# Load the default path if no paths are specified:
	paths ||= Dir.glob(Covered::Persist::DEFAULT_PATH, base: context.root)
	
	# If no paths are specified, raise an error:
	if paths.empty?
		raise ArgumentError, "No coverage paths specified!"
	end
	
	# Load all coverage information:
	paths.each do |path|
		# It would be nice to have a better algorithm here than just ignoring mtime - perhaps using checksums?
		Covered::Persist.new(policy.output, path).load!(ignore_mtime: true)
	end
	
	return policy
end

# Validate the coverage of multiple test runs.
# @parameter paths [Array(String)] The coverage database paths.
# @parameter minimum [Float] The minimum required coverage in order to pass.
# @parameter input [Covered::Policy] The input policy to validate.
def statistics(paths: nil, minimum: 1.0, input:)
	policy ||= context.lookup("covered:policy:current").call(paths: paths)
	
	# Calculate statistics:
	statistics = Covered::Statistics.new
	
	policy.each do |coverage|
		statistics << coverage
	end
	
	return statistics
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
covered-0.24.2 bake/covered/policy.rb