-
Notifications
You must be signed in to change notification settings - Fork 238
/
Rakefile
53 lines (43 loc) · 1.27 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rake/clean'
CLEAN << 'pkg'
CLEAN << 'test/output/*'
desc 'Run tests'
task default: :test
Rake::TestTask.new
namespace :test do
desc 'Update expected image with output'
task :'image:update' do
require 'rmagick'
require 'fileutils'
update_expected_images = lambda do |expect_dir, output_dir|
Dir.glob("#{output_dir}/*.png").each do |output_path|
file_name = File.basename(output_path)
expected_path = "#{expect_dir}/#{file_name}"
error = nil
output_image = Magick::Image.read(output_path).first
if File.exist?(expected_path)
expected_image = Magick::Image.read(expected_path).first
retry_count = 0
begin
_, error = expected_image.compare_channel(output_image, Magick::PeakAbsoluteErrorMetric)
rescue StandardError => e
GC.start
if retry_count < 5
retry_count += 1
retry
else
raise e
end
end
end
if error != 0.0
FileUtils.copy(output_path, expected_path)
end
end
end
update_expected_images.call('test/expected', 'test/output')
end
end