diff --git a/activestorage-hotcell-client/test/test_helper.rb b/activestorage-hotcell-client/test/test_helper.rb index 35731d6..1998a0b 100644 --- a/activestorage-hotcell-client/test/test_helper.rb +++ b/activestorage-hotcell-client/test/test_helper.rb @@ -21,6 +21,9 @@ class TemporarilyUnavailable < StandardError; end FIXTURES = File.expand_path("../../activestorage-hotcell-server/test/fixtures", __dir__) + # ImageMagick 7 runs `magick identify`; ImageMagick 6 has `identify` and no `magick`. + IDENTIFY = system("magick", "-version", out: File::NULL, err: File::NULL) ? %w[ magick identify ] : %w[ identify ] + def setup HotCell.reset_registrations! HotCell.logger = Logger.new(File::NULL) @@ -96,7 +99,7 @@ def with_active_storage_setting(name, value) end def identify(path) - lines = `magick identify -format '%w %h %m\n' #{path.shellescape} 2>/dev/null`.lines + lines = `#{IDENTIFY.shelljoin} -format '%w %h %m\n' #{path.shellescape} 2>/dev/null`.lines skip "ImageMagick is not installed" if lines.empty? width, height, format = lines.first.split diff --git a/activestorage-hotcell-server/test/magick_environment_test.rb b/activestorage-hotcell-server/test/magick_environment_test.rb index c7ca575..1b09e87 100644 --- a/activestorage-hotcell-server/test/magick_environment_test.rb +++ b/activestorage-hotcell-server/test/magick_environment_test.rb @@ -34,8 +34,10 @@ def test_magick_does_not_inherit_the_workers_environment # The premise. Handed the same variable, `magick` in this process does refuse the fixture — so the # assertion above cannot pass because the policy was ineffective. def test_the_policy_does_refuse_a_magick_that_reads_it + skip "ImageMagick is not installed" unless magick_installed? + with_refusing_policy_in_the_environment do |directory| - refused = system({ "MAGICK_CONFIGURE_PATH" => directory }, "magick", "identify", fixture("colour.png"), + refused = system({ "MAGICK_CONFIGURE_PATH" => directory }, *IDENTIFY, fixture("colour.png"), out: File::NULL, err: File::NULL) refute refused, "the policy did not refuse PNG, so this test proves nothing" @@ -176,14 +178,12 @@ def in_a_child(environment, script) # Both sides start from no bound at all: a runner holding one of its own would otherwise compare a # bounded pool against a bounded pool. def magick_installed? - system "magick", "-version", out: File::NULL, err: File::NULL - rescue Errno::ENOENT - false + system(*IDENTIFY, "-version", out: File::NULL, err: File::NULL) end def magick_thread_resource(environment) environment = { "OMP_NUM_THREADS" => nil, "OMP_THREAD_LIMIT" => nil }.merge(environment) - output = IO.popen([ environment, "magick", "-list", "resource" ], &:read) + output = IO.popen([ environment, *IDENTIFY, "-list", "resource" ], &:read) Integer(output[/Thread: (\d+)/, 1]) rescue Errno::ENOENT diff --git a/activestorage-hotcell-server/test/previewers_test.rb b/activestorage-hotcell-server/test/previewers_test.rb index b0456b5..f85b584 100644 --- a/activestorage-hotcell-server/test/previewers_test.rb +++ b/activestorage-hotcell-server/test/previewers_test.rb @@ -269,7 +269,7 @@ def test_a_preview_reports_no_dimensions_because_rails_previewers_do_not_either # Mean intensity over the whole image, 0 black to 1 white, from ImageMagick so the claim does not come # from the toolchain that produced the bytes. def brightness(path) - value = `magick identify -format '%[fx:mean]' #{path.shellescape} 2>/dev/null` + value = `#{IDENTIFY.shelljoin} -format '%[fx:mean]' #{path.shellescape} 2>/dev/null` skip "ImageMagick is not installed" if value.empty? Float(value) diff --git a/activestorage-hotcell-server/test/test_helper.rb b/activestorage-hotcell-server/test/test_helper.rb index b588941..1a635b1 100644 --- a/activestorage-hotcell-server/test/test_helper.rb +++ b/activestorage-hotcell-server/test/test_helper.rb @@ -20,6 +20,9 @@ class ActiveStorageHotCellTest < Minitest::Test FIXTURES = File.expand_path("fixtures", __dir__) + # ImageMagick 7 runs `magick identify`; ImageMagick 6 has `identify` and no `magick`. + IDENTIFY = system("magick", "-version", out: File::NULL, err: File::NULL) ? %w[ magick identify ] : %w[ identify ] + private def fixture(name) File.join FIXTURES, name @@ -51,7 +54,7 @@ def assert_failed(code, response, cause: nil) # One line per frame, and a format string is repeated once per frame too — which is how the first version of # this read a frame count out of the wrong token and blamed the operation for it. def identify(path) - lines = `magick identify -format '%w %h %m\n' #{path.shellescape} 2>/dev/null`.lines + lines = `#{IDENTIFY.shelljoin} -format '%w %h %m\n' #{path.shellescape} 2>/dev/null`.lines skip "ImageMagick is not installed" if lines.empty? width, height, format = lines.first.split