# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2022-2026, by Samuel Williams.

def initialize(context)
	super
	
	require_relative "../../lib/covered/config"
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 validate(paths: nil, minimum: 1.0, input:)
	input ||= context.lookup("covered:policy:current").call(paths: paths)
	
	# Calculate statistics:
	statistics = Covered::Statistics.new
	
	input.each do |coverage|
		statistics << coverage
	end
	
	input.call(STDOUT)
	
	# Validate statistics and raise an error if they are not met:
	statistics.validate!(minimum)
end
