bake/covered/validate.rb in covered-0.22.0 vs bake/covered/validate.rb in covered-0.22.1
- old
+ new
@@ -13,20 +13,32 @@
# @parameter paths [Array(String)] The coverage database paths.
# @parameter minimum [Float] The minimum required coverage in order to pass.
def validate(paths: nil, minimum: 1.0)
policy = Covered::Policy.new
- paths&.each do |path|
+ # 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
+ # Calculate statistics:
statistics = Covered::Statistics.new
policy.each do |coverage|
statistics << coverage
end
+ # Print statistics:
statistics.print($stderr)
+ # Validate statistics and raise an error if they are not met:
statistics.validate!(minimum)
end