mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00

Not thread safe! But I don't think we care. We want to evaluate the env DSL block in the context of ENV for asthetic reasons, but we also want access to methods on the requirement instance. We can use #instance_exec to pass the requirement itself into the block: class Foo < Requirement env do |req| append 'PATH', req.some_path end def some_path which 'something' end end Also add a simplified version of Object#instance_exec for Ruby 1.8.6.
70 lines
1.4 KiB
Ruby
70 lines
1.4 KiB
Ruby
require 'testing_env'
|
|
require 'build_environment'
|
|
|
|
class BuildEnvironmentTests < Test::Unit::TestCase
|
|
def setup
|
|
@env = BuildEnvironment.new
|
|
end
|
|
|
|
def test_shovel_returns_self
|
|
assert_same @env, (@env << :foo)
|
|
end
|
|
|
|
def test_std?
|
|
@env << :std
|
|
assert @env.std?
|
|
end
|
|
|
|
def test_userpaths?
|
|
@env << :userpaths
|
|
assert @env.userpaths?
|
|
end
|
|
|
|
def test_modify_build_environment
|
|
@env << Proc.new { 1 }
|
|
assert_equal 1, @env.modify_build_environment
|
|
end
|
|
|
|
def test_marshal
|
|
@env << :userpaths
|
|
@env << Proc.new { 1 }
|
|
dump = Marshal.dump(@env)
|
|
assert Marshal.load(dump).userpaths?
|
|
end
|
|
|
|
def test_env_block
|
|
foo = mock("foo")
|
|
@env << Proc.new { foo.some_message }
|
|
foo.expects(:some_message)
|
|
@env.modify_build_environment
|
|
end
|
|
|
|
def test_env_block_with_argument
|
|
foo = mock("foo")
|
|
@env << Proc.new { |x| x.some_message }
|
|
foo.expects(:some_message)
|
|
@env.modify_build_environment(foo)
|
|
end
|
|
end
|
|
|
|
class BuildEnvironmentDSLTests < Test::Unit::TestCase
|
|
def make_instance(&block)
|
|
Class.new do
|
|
extend BuildEnvironmentDSL
|
|
def env; self.class.env end
|
|
class_eval(&block)
|
|
end.new
|
|
end
|
|
|
|
def test_env_single_argument
|
|
obj = make_instance { env :userpaths }
|
|
assert obj.env.userpaths?
|
|
end
|
|
|
|
def test_env_multiple_arguments
|
|
obj = make_instance { env :userpaths, :std }
|
|
assert obj.env.userpaths?
|
|
assert obj.env.std?
|
|
end
|
|
end
|