diff --git a/Library/Homebrew/test/inreplace_spec.rb b/Library/Homebrew/test/inreplace_spec.rb index 55edc5437e..7b5901b94a 100644 --- a/Library/Homebrew/test/inreplace_spec.rb +++ b/Library/Homebrew/test/inreplace_spec.rb @@ -228,6 +228,12 @@ describe Utils::Inreplace do after { file.unlink } + it "raises error if there are no files given to replace" do + expect { + described_class.inreplace [], "d", "f" + }.to raise_error(Utils::InreplaceError) + end + it "raises error if there is nothing to replace" do expect { described_class.inreplace file.path, "d", "f" diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index 3bce563f7c..59f2552679 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -22,6 +22,8 @@ module Utils def inreplace(paths, before = nil, after = nil, audit_result = true) errors = {} + errors["`paths` (first) parameter"] = ["`paths` was empty"] if paths.blank? + Array(paths).each do |path| s = File.open(path, "rb", &:read).extend(StringInreplaceExtension)