diff options
| author | Mike McQuaid | 2017-08-12 13:00:10 +0100 |
|---|---|---|
| committer | GitHub | 2017-08-12 13:00:10 +0100 |
| commit | b93f1e356990c4e7a12517edb479ddeab9b27978 (patch) | |
| tree | 96e11905045a02fbf97aa127e081c940b308351e /Library | |
| parent | 7ecc7758484d3d8e7b3becc3735affe50f4b3898 (diff) | |
| parent | 4760f4e8032694d37f934257f6a58f0164438151 (diff) | |
| download | brew-b93f1e356990c4e7a12517edb479ddeab9b27978.tar.bz2 | |
Merge pull request #3046 from alyssais/double_formula_load_error
Raise an exception when double loading a formula
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/formulary.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/test/formulary_spec.rb | 10 |
2 files changed, 12 insertions, 0 deletions
diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index dd67b4f24..b26846e00 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -20,6 +20,8 @@ module Formulary raise "Formula loading disabled by HOMEBREW_DISABLE_LOAD_FORMULA!" end + raise "Formula #{name} has already been loaded" if const_defined?(namespace) + mod = Module.new const_set(namespace, mod) begin diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 234ebc93c..7a7c8811a 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -27,6 +27,16 @@ describe Formulary do let(:bottle_dir) { Pathname.new("#{TEST_FIXTURE_DIR}/bottles") } let(:bottle) { bottle_dir/"testball_bottle-0.1.#{Utils::Bottles.tag}.bottle.tar.gz" } + describe "::load_formula" do + it "does not allow namespace repetition" do |example| + definition = "Foo = Class.new(Formula)" + namespace = "Test#{example.description.hash.abs}" + subject.load_formula("foo", "bar", definition, namespace) + expect { subject.load_formula("foo", "bar", definition, namespace) } + .to raise_error RuntimeError, /already.* loaded/ + end + end + describe "::class_s" do it "replaces '+' with 'x'" do expect(subject.class_s("foo++")).to eq("Fooxx") |
