diff options
| author | Jack Nagel | 2013-10-22 13:07:08 -0500 |
|---|---|---|
| committer | Jack Nagel | 2013-10-22 13:31:08 -0500 |
| commit | fcf616c380d749d6fc40212626c6d9abfa46ce49 (patch) | |
| tree | e473f69df16b83f8dd4a318faceaccdb9092b339 /Library/Homebrew/test | |
| parent | abad65940d22a759261a9285424706cdc38c1275 (diff) | |
| download | homebrew-fcf616c380d749d6fc40212626c6d9abfa46ce49.tar.bz2 | |
Eagerly initialize formula specs
Declarations of dependencies, options, and resources in the DSL only
apply to specs that have already been initialized. For example, given
this snippet:
url ...
sha1 ...
depends_on 'foo'
devel do
url ...
sha1 ...
end
The dependency 'foo' will be recorded for the stable spec, but not the
devel spec, since it was not initialized prior to the call to
depends_on.
While it is considered best practice to declare all specs (stable,
devel, head, and bottle) prior to other declarations, there is nothing
that enforces this ordering, so when it happens it can be confusing and
hard to debug.
To prevent this, we can initialize all specs up front. This comes with
a performance penalty for commands that load all formulae into memory,
but that is probably outweighed by what we gain in correctness.
Fixes #23425.
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/test_formula.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb index bc1e703eb..00f929e4b 100644 --- a/Library/Homebrew/test/test_formula.rb +++ b/Library/Homebrew/test/test_formula.rb @@ -212,4 +212,30 @@ class FormulaTests < Test::Unit::TestCase ensure path.unlink end + + def test_class_specs_are_always_initialized + f = formula { url 'foo-1.0' } + + %w{stable devel head bottle}.each do |spec| + assert_kind_of SoftwareSpec, f.class.send(spec) + end + end + + def test_incomplete_instance_specs_are_not_accessible + f = formula { url 'foo-1.0' } + + %w{devel head bottle}.each { |spec| assert_nil f.send(spec) } + end + + def test_honors_attributes_declared_before_specs + f = formula do + url 'foo-1.0' + depends_on 'foo' + devel { url 'foo-1.1' } + end + + %w{stable devel head bottle}.each do |spec| + assert_equal 'foo', f.class.send(spec).deps.first.name + end + end end |
