remove_make_var! should not leave an empty assignment
This commit is contained in:
parent
07adef4954
commit
6671d6275d
@ -14,13 +14,21 @@ class InreplaceTest < Test::Unit::TestCase
|
||||
s1.change_make_var! "FLAG", "\\1 def"
|
||||
assert_equal "FLAG=abc def", s1
|
||||
end
|
||||
|
||||
def test_change_make_var_shell_style
|
||||
# Shell variables have no spaces around =
|
||||
s1="FLAG=abc"
|
||||
s1.extend(HomebrewInreplaceExtension)
|
||||
s1.change_make_var! "FLAG", "def"
|
||||
assert_equal "FLAG=def", s1
|
||||
end
|
||||
|
||||
def test_remove_make_var
|
||||
# Replace flag
|
||||
s1="FLAG = abc\nFLAG2 = def"
|
||||
s1.extend(HomebrewInreplaceExtension)
|
||||
s1.remove_make_var! "FLAG"
|
||||
assert_equal "FLAG=\nFLAG2 = def", s1
|
||||
assert_equal "FLAG2 = def", s1
|
||||
end
|
||||
|
||||
def test_remove_make_vars
|
||||
@ -28,6 +36,6 @@ class InreplaceTest < Test::Unit::TestCase
|
||||
s1="FLAG = abc\nFLAG2 = def"
|
||||
s1.extend(HomebrewInreplaceExtension)
|
||||
s1.remove_make_var! ["FLAG", "FLAG2"]
|
||||
assert_equal "FLAG=\nFLAG2=", s1
|
||||
assert_equal "", s1
|
||||
end
|
||||
end
|
||||
|
||||
@ -177,16 +177,20 @@ def archs_for_command cmd
|
||||
end
|
||||
end
|
||||
|
||||
# String extensions added by inreplace below.
|
||||
module HomebrewInreplaceExtension
|
||||
# Looks for Makefile style variable defintions and replaces the
|
||||
# value with "new_value", or removes the definition entirely.
|
||||
# See inreplace in utils.rb
|
||||
def change_make_var! flag, new_value=nil
|
||||
new_value = "#{flag}=#{new_value}" unless new_value == nil
|
||||
def change_make_var! flag, new_value
|
||||
new_value = "#{flag}=#{new_value}"
|
||||
gsub! Regexp.new("^#{flag}\\s*=\\s*(.*)$"), new_value
|
||||
end
|
||||
# Removes variable assignments completely.
|
||||
def remove_make_var! flags
|
||||
flags.each { |flag| change_make_var! flag, "" }
|
||||
flags.each do |flag|
|
||||
# Also remove trailing \n, if present.
|
||||
gsub! Regexp.new("^#{flag}\\s*=(.*)$\n?"), ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user