Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion activestorage-hotcell-client/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions activestorage-hotcell-server/test/magick_environment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Comment thread
flavorjones marked this conversation as resolved.
out: File::NULL, err: File::NULL)

refute refused, "the policy did not refuse PNG, so this test proves nothing"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion activestorage-hotcell-server/test/previewers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion activestorage-hotcell-server/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading