diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 0a09045623..80631d86c2 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -8,6 +8,7 @@ class AbstractDownloadStrategy end def expand_safe_system_args args + args = args.dup args.each_with_index do |arg, ii| if arg.is_a? Hash unless ARGV.verbose? @@ -20,7 +21,7 @@ class AbstractDownloadStrategy end # 2 as default because commands are eg. svn up, git pull args.insert(2, '-q') unless ARGV.verbose? - return args + args end def quiet_safe_system *args diff --git a/Library/Homebrew/test/test_download_strategies.rb b/Library/Homebrew/test/test_download_strategies.rb index 13392272b9..fcef2a2821 100644 --- a/Library/Homebrew/test/test_download_strategies.rb +++ b/Library/Homebrew/test/test_download_strategies.rb @@ -1,6 +1,42 @@ require 'testing_env' require 'download_strategy' require 'bottles' # XXX: hoist these regexps into constants in Pathname? +require 'hardware' # XXX: wat. fix this require mess! + +class SoftwareSpecDouble + attr_reader :url, :specs + + def initialize(url="http://foo.com/bar.tar.gz", specs={}) + @url = url + @specs = specs + end +end + +class AbstractDownloadStrategyTests < Test::Unit::TestCase + def setup + @name = "foo" + @package = SoftwareSpecDouble.new + @strategy = AbstractDownloadStrategy.new(@name, @package) + @args = %w{foo bar baz} + end + + def test_expand_safe_system_args_with_explicit_quiet_flag + @args << { :quiet_flag => '--flag' } + expanded_args = @strategy.expand_safe_system_args(@args) + assert_equal %w{foo bar baz --flag}, expanded_args + end + + def test_expand_safe_system_args_with_implicit_quiet_flag + expanded_args = @strategy.expand_safe_system_args(@args) + assert_equal %w{foo bar -q baz}, expanded_args + end + + def test_expand_safe_system_args_does_not_mutate_argument + result = @strategy.expand_safe_system_args(@args) + assert_equal %w{foo bar baz}, @args + assert_not_same @args, result + end +end class DownloadStrategyDetectorTests < Test::Unit::TestCase def setup