Merge pull request #14416 from lucaong/avoid-mutating-script-argument
Avoid mutating the script argument in place
This commit is contained in:
commit
daecb93d22
@ -99,7 +99,12 @@ module Cask
|
|||||||
description = key ? "#{stanza} #{key.inspect}" : stanza.to_s
|
description = key ? "#{stanza} #{key.inspect}" : stanza.to_s
|
||||||
|
|
||||||
# backward-compatible string value
|
# backward-compatible string value
|
||||||
arguments = { executable: arguments } if arguments.is_a?(String)
|
arguments = if arguments.is_a?(String)
|
||||||
|
{ executable: arguments }
|
||||||
|
else
|
||||||
|
# Avoid mutating the original argument
|
||||||
|
arguments.dup
|
||||||
|
end
|
||||||
|
|
||||||
# key sanity
|
# key sanity
|
||||||
permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :print_stdout, :print_stderr]
|
permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :print_stdout, :print_stderr]
|
||||||
|
|||||||
@ -0,0 +1,29 @@
|
|||||||
|
# typed: false
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe Cask::Artifact::AbstractArtifact, :cask do
|
||||||
|
describe ".read_script_arguments" do
|
||||||
|
let(:stanza) { :installer }
|
||||||
|
|
||||||
|
it "accepts a string, and uses it as the executable" do
|
||||||
|
arguments = "something"
|
||||||
|
|
||||||
|
expect(described_class.read_script_arguments(arguments, stanza)).to eq(["something", {}])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "accepts a hash with an executable" do
|
||||||
|
arguments = { executable: "something" }
|
||||||
|
|
||||||
|
expect(described_class.read_script_arguments(arguments, stanza)).to eq(["something", {}])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not mutate the original arguments in place" do
|
||||||
|
arguments = { executable: "something" }
|
||||||
|
clone = arguments.dup
|
||||||
|
|
||||||
|
described_class.read_script_arguments(arguments, stanza)
|
||||||
|
|
||||||
|
expect(arguments).to eq(clone)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user