Skip to content

Commit 759f54c

Browse files
committed
fix calls to shellescape and cleanup checking exit codes
1 parent 2a843db commit 759f54c

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

script/worker_analysis

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ Process.times.class.class_eval do
8181
end
8282

8383
ImageOptim::Path.class_eval do
84-
def shellescape
85-
to_s.shellescape
86-
end
87-
8884
def digest
8985
@digest ||= Digest::SHA256.file(to_s).hexdigest
9086
end
@@ -313,22 +309,21 @@ class Analyser
313309
images = [flatten_animation(@path), flatten_animation(other)]
314310

315311
alpha_presence = images.map do |image|
316-
Cmd.capture("identify -format '%A' #{image.shellescape}")
312+
Cmd.capture("identify -format '%A' #{image.to_s.shellescape}")
317313
end
318314
if alpha_presence.uniq.length == 2
319315
images.map!{ |image| underlay_noise(image) }
320316
end
321317

322-
nrmse_command = %W[
318+
nrmse = Cmd.capture(*%W[
323319
convert
324320
#{images[0]} -auto-orient
325321
#{images[1]} -auto-orient
326322
-metric RMSE
327323
-compare
328324
-format %[distortion]
329325
info:
330-
].shelljoin
331-
nrmse = Cmd.capture(nrmse_command).to_f
326+
]).to_f
332327
unless $CHILD_STATUS.success?
333328
fail "failed comparison of #{@path} with #{other}"
334329
end
@@ -342,14 +337,11 @@ class Analyser
342337
flattened = image.temp_path
343338
Cmd.run(*%W[
344339
convert
345-
#{image.shellescape}
340+
#{image}
346341
-coalesce
347342
-append
348-
#{flattened.shellescape}
349-
])
350-
unless $CHILD_STATUS.success?
351-
fail "failed flattening of #{image}"
352-
end
343+
#{flattened}
344+
]) || fail("failed flattening of #{image}")
353345
flattened
354346
else
355347
image
@@ -362,16 +354,13 @@ class Analyser
362354
with_noise = image.temp_path
363355
Cmd.run(*%W[
364356
convert
365-
#{image.shellescape}
357+
#{image}
366358
+noise Random
367-
#{image.shellescape}
359+
#{image}
368360
-flatten
369361
-alpha off
370-
#{with_noise.shellescape}
371-
])
372-
unless $CHILD_STATUS.success?
373-
fail "failed underlaying noise to #{image}"
374-
end
362+
#{with_noise}
363+
]) || fail("failed underlaying noise to #{image}")
375364
with_noise
376365
end
377366
end

spec/spec_helper.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def flatten_animation(image)
2626
flattened = image.temp_path
2727
command = %W[
2828
convert
29-
#{image.to_s.shellescape}
29+
#{image}
3030
-coalesce
3131
-append
32-
#{flattened.to_s.shellescape}
33-
].join(' ')
32+
#{flattened}
33+
].shelljoin
3434
expect(ImageOptim::Cmd.run(command)).to be_truthy
3535
flattened
3636
else
@@ -41,16 +41,15 @@ def flatten_animation(image)
4141
def mepp(image_a, image_b)
4242
coalesce_a = flatten_animation(image_a)
4343
coalesce_b = flatten_animation(image_b)
44-
command = %W[
44+
output = ImageOptim::Cmd.capture(%W[
4545
compare
4646
-metric MEPP
4747
-alpha Background
4848
#{coalesce_a.to_s.shellescape}
4949
#{coalesce_b.to_s.shellescape}
5050
#{ImageOptim::Path::NULL}
5151
2>&1
52-
].join(' ')
53-
output = ImageOptim::Cmd.capture(command)
52+
].join(' '))
5453
unless [0, 1].include?($CHILD_STATUS.exitstatus)
5554
fail "compare #{image_a} with #{image_b} failed with `#{output}`"
5655
end

0 commit comments

Comments
 (0)