Skip to content

Commit

Permalink
Rename coverage -> reports and expose it in validate task. (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix authored Jul 11, 2024
1 parent 9fad7af commit 755aca6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
6 changes: 5 additions & 1 deletion bake/covered/policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(context)
# 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)
def current(paths: nil, reports: Covered::Config.reports)
policy = Covered::Policy.new

# Load the default path if no paths are specified:
Expand All @@ -30,6 +30,10 @@ def current(paths: nil)
Covered::Persist.new(policy.output, path).load!(ignore_mtime: true)
end

if reports
policy.reports!(reports)
end

return policy
end

Expand Down
2 changes: 2 additions & 0 deletions bake/covered/validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def validate(paths: nil, minimum: 1.0, input:)
# Print statistics:
statistics.print($stderr)

policy.call(STDOUT)

# Validate statistics and raise an error if they are not met:
statistics.validate!(minimum)
end
18 changes: 10 additions & 8 deletions lib/covered/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def self.path(root)
end
end

def self.coverage
ENV['COVERAGE']
def self.reports
ENV.fetch('COVERED_REPORTS') do
ENV['COVERAGE']
end
end

def self.load(root: self.root, coverage: self.coverage)
def self.load(root: self.root, reports: self.reports)
derived = Class.new(self)

if path = self.path(root)
Expand All @@ -34,19 +36,19 @@ def self.load(root: self.root, coverage: self.coverage)
derived.prepend(config)
end

return derived.new(root, coverage)
return derived.new(root, reports)
end

def initialize(root, coverage)
def initialize(root, reports)
@root = root
@coverage = coverage
@reports = reports
@policy = nil

@environment = nil
end

def report?
!!@coverage
!!@reports
end

alias :record? :report?
Expand Down Expand Up @@ -108,7 +110,7 @@ def make_policy(policy)

policy.persist!

policy.reports!(@coverage)
policy.reports!(@reports)
end

protected
Expand Down
14 changes: 10 additions & 4 deletions lib/covered/policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def snake_case(string)
end
end

def reports!(coverage)
if coverage.is_a?(String)
names = coverage.split(',')
def reports!(reports)
if reports.is_a?(String)
names = reports.split(',')

names.each do |name|
begin
Expand All @@ -113,8 +113,14 @@ def reports!(coverage)
@reports << Autoload.new(name)
end
end
elsif coverage
elsif reports == true
@reports << Covered::BriefSummary.new
elsif reports == false
@reports.clear
elsif reports.is_a?(Array)
@reports.concat(reports)
else
@reports << reports
end
end

Expand Down

0 comments on commit 755aca6

Please sign in to comment.