Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
c66b840f
Commit
c66b840f
authored
8 years ago
by
Markus Reiter
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #2209 from reitermarkus/spec-formula_installer
Convert FormulaInstaller test to spec.
parents
dbdd39b1
8b60412c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Library/Homebrew/test/formula_installer_spec.rb
+137
-0
137 additions, 0 deletions
Library/Homebrew/test/formula_installer_spec.rb
with
137 additions
and
0 deletions
Library/Homebrew/test/formula_installer_
test
.rb
→
Library/Homebrew/test/formula_installer_
spec
.rb
+
137
−
0
View file @
c66b840f
require
"testing_env"
require
"formula"
require
"formula_installer"
require
"keg"
...
...
@@ -6,21 +5,30 @@ require "tab"
require
"test/support/fixtures/testball"
require
"test/support/fixtures/testball_bottle"
class
InstallTests
<
Homebrew
::
TestCase
RSpec
::
Matchers
.
define_negated_matcher
:need_bottle
,
:be_bottle_unneeded
RSpec
::
Matchers
.
alias_matcher
:have_disabled_bottle
,
:be_bottle_disabled
describe
FormulaInstaller
do
matcher
:be_poured_from_bottle
do
match
(
&
:poured_from_bottle
)
end
def
temporary_install
(
formula
)
refute_predicate
formula
,
:
installed
?
expect
(
formula
).
not_to
be_
installed
installer
=
FormulaInstaller
.
new
(
formula
)
installer
=
described_class
.
new
(
formula
)
shutup
{
installer
.
install
}
shutup
do
installer
.
install
end
keg
=
Keg
.
new
(
formula
.
prefix
)
assert_predicate
formula
,
:
installed
?
expect
(
formula
).
to
be_
installed
begin
Tab
.
clear_cache
refute_predicate
Tab
.
for_keg
(
keg
)
,
:
poured_from_bottle
expect
(
Tab
.
for_keg
(
keg
)
).
not_to
be_
poured_from_bottle
yield
formula
ensure
...
...
@@ -32,68 +40,66 @@ class InstallTests < Homebrew::TestCase
formula
.
logs
.
rmtree
if
formula
.
logs
.
directory?
end
refute_predicate
keg
,
:
exist
?
refute_predicate
formula
,
:
installed
?
expect
(
keg
).
not_to
exist
expect
(
formula
).
not_to
be_
installed
end
def
test_a_
basic
_
install
specify
"
basic
install
ation"
do
ARGV
<<
"--with-invalid_flag"
# added to ensure it doesn't fail install
temporary_install
(
Testball
.
new
)
do
|
f
|
# Test that things made it into the Keg
assert_predicate
f
.
prefix
+
"readme"
,
:
exist
?
expect
(
f
.
prefix
/
"readme"
).
to
exist
assert_predicate
f
.
bin
,
:
directory
?
assert_equal
3
,
f
.
bin
.
children
.
length
expect
(
f
.
bin
).
to
be_a_
directory
expect
(
f
.
bin
.
children
.
count
).
to
eq
(
3
)
assert_predicate
f
.
libexec
,
:
directory
?
assert_equal
1
,
f
.
libexec
.
children
.
length
expect
(
f
.
libexec
).
to
be_a_
directory
expect
(
f
.
libexec
.
children
.
count
).
to
eq
(
1
)
refute_predicate
f
.
prefix
+
"main.c"
,
:exist?
refute_predicate
f
.
prefix
+
"license"
,
:exist?
expect
(
f
.
prefix
/
"main.c"
).
not_to
exist
expect
(
f
.
prefix
/
"license"
).
not_to
exist
# Test that things make it into the Cellar
keg
=
Keg
.
new
f
.
prefix
keg
.
link
bin
=
HOMEBREW_PREFIX
+
"bin"
assert_predicate
bin
,
:
directory
?
assert_equal
3
,
bin
.
children
.
length
assert_predicate
f
.
prefix
/
".brew/testball.rb"
,
:
readable
?
bin
=
HOMEBREW_PREFIX
/
"bin"
expect
(
bin
).
to
be_a_
directory
expect
(
bin
.
children
.
count
).
to
eq
(
3
)
expect
(
f
.
prefix
/
".brew/testball.rb"
).
to
be_
readable
end
end
def
test_bottle_unneeded_formula_install
DevelopmentTools
.
stubs
(
:installed?
).
return
s
(
false
)
specify
"Formula installation with unneeded bottle"
do
allow
(
DevelopmentTools
).
to
receive
(
:installed?
).
and_
return
(
false
)
formula
=
Testball
.
new
formula
.
stubs
(
:bottle_unneeded?
).
return
s
(
true
)
formula
.
stubs
(
:bottle_disabled?
).
return
s
(
true
)
allow
(
formula
).
to
receive
(
:bottle_unneeded?
).
and_
return
(
true
)
allow
(
formula
).
to
receive
(
:bottle_disabled?
).
and_
return
(
true
)
refute_predicate
formula
,
:
bottled
?
assert_predicate
formula
,
:bottle_unneeded?
assert_predicate
formula
,
:bottl
e_disabled
?
expect
(
formula
).
not_to
be_
bottled
expect
(
formula
).
not_to
need_bottle
expect
(
formula
).
to
hav
e_disabled
_bottle
temporary_install
(
formula
)
do
|
f
|
assert_predicate
f
,
:
installed
?
expect
(
f
).
to
be_
installed
end
end
def
test_
not
_
poured
_
from
_
bottle
_
when
_
compiler
_
specified
assert_nil
ARGV
.
cc
specify
"Formula is
not
poured
from
bottle
when
compiler
specified
"
do
expect
(
ARGV
.
cc
).
to
be
nil
cc_arg
=
"--cc=clang"
ARGV
<<
cc_arg
temporary_install
(
TestballBottle
.
new
)
do
|
f
|
tab
=
Tab
.
for_formula
(
f
)
assert_equal
"clang"
,
tab
.
compiler
expect
(
tab
.
compiler
).
to
eq
(
"clang"
)
end
end
end
class
FormulaInstallerTests
<
Homebrew
::
TestCase
def
test_check_install_sanity_pinned_dep
specify
"check installation sanity pinned dependency"
do
dep_name
=
"dependency"
dep_path
=
CoreTap
.
new
.
formula_dir
/
"
#{
dep_name
}
.rb"
dep_path
.
write
<<-
EOS
.
undent
...
...
@@ -112,20 +118,20 @@ class FormulaInstallerTests < Homebrew::TestCase
depends_on
dependency
.
name
.
to_s
end
dependency
.
prefix
(
"0.1"
)
.
join
(
"bin
/
a"
).
mkpath
(
dependency
.
prefix
(
"0.1"
)
/
"bin
"
/
"
a"
).
mkpath
HOMEBREW_PINNED_KEGS
.
mkpath
FileUtils
.
ln_s
dependency
.
prefix
(
"0.1"
),
HOMEBREW_PINNED_KEGS
/
dep_name
dependency_keg
=
Keg
.
new
(
dependency
.
prefix
(
"0.1"
))
dependency_keg
.
link
assert_predicate
dependency_keg
,
:
linked
?
assert_predicate
dependency
,
:
pinned
?
expect
(
dependency_keg
).
to
be_
linked
expect
(
dependency
).
to
be_
pinned
fi
=
FormulaInstaller
.
new
(
dependent
)
assert_raises
(
CannotInstallFormulaError
)
{
fi
.
check_install_sanity
}
e
nsure
dependency_keg
.
unlink
Formulary
::
FORMULAE
.
delete
(
dep_path
)
e
xpect
{
fi
.
check_install_sanity
}.
to
raise_error
(
CannotInstallFormulaError
)
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment