2010-03-20 23:13:25 -07:00
|
|
|
require 'testing_env'
|
2013-08-19 12:32:59 -05:00
|
|
|
require 'extend/ENV'
|
2012-06-20 00:51:01 -05:00
|
|
|
|
2010-03-20 23:13:25 -07:00
|
|
|
class EnvironmentTests < Test::Unit::TestCase
|
2013-08-19 12:32:59 -05:00
|
|
|
def setup
|
|
|
|
@env = {}.extend(EnvActivation)
|
|
|
|
@env.activate_extensions!
|
|
|
|
end
|
|
|
|
|
2010-03-20 23:13:25 -07:00
|
|
|
def test_ENV_options
|
2013-08-19 12:32:59 -05:00
|
|
|
@env.gcc_4_0
|
|
|
|
@env.O3
|
|
|
|
@env.minimal_optimization
|
|
|
|
@env.no_optimization
|
|
|
|
@env.libxml2
|
|
|
|
@env.enable_warnings
|
|
|
|
assert !@env.cc.empty?
|
|
|
|
assert !@env.cxx.empty?
|
2010-03-20 23:13:25 -07:00
|
|
|
end
|
2012-03-21 12:01:19 -05:00
|
|
|
|
|
|
|
def test_switching_compilers
|
2013-08-19 12:32:59 -05:00
|
|
|
@env.llvm
|
|
|
|
@env.clang
|
|
|
|
assert_nil @env['LD']
|
|
|
|
assert_equal @env['OBJC'], @env['CC']
|
2012-03-21 12:01:19 -05:00
|
|
|
end
|
2013-01-19 20:45:57 -06:00
|
|
|
|
2013-01-22 04:32:26 -06:00
|
|
|
def test_with_build_environment_restores_env
|
2013-08-19 12:32:59 -05:00
|
|
|
before = @env.dup
|
|
|
|
@env.with_build_environment do
|
|
|
|
@env['foo'] = 'bar'
|
2013-01-19 20:45:57 -06:00
|
|
|
end
|
2013-08-19 12:32:59 -05:00
|
|
|
assert_nil @env['foo']
|
|
|
|
assert_equal before, @env
|
2013-01-19 20:45:57 -06:00
|
|
|
end
|
2013-01-22 04:32:26 -06:00
|
|
|
|
|
|
|
def test_with_build_environment_ensures_env_restored
|
2013-08-19 12:32:59 -05:00
|
|
|
before = @env.dup
|
2013-01-22 04:32:26 -06:00
|
|
|
begin
|
2013-08-19 12:32:59 -05:00
|
|
|
@env.with_build_environment do
|
|
|
|
@env['foo'] = 'bar'
|
|
|
|
raise Exception
|
|
|
|
end
|
2013-01-22 04:32:26 -06:00
|
|
|
rescue Exception
|
|
|
|
end
|
2013-08-19 12:32:59 -05:00
|
|
|
assert_nil @env['foo']
|
|
|
|
assert_equal before, @env
|
2013-01-22 04:32:26 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_with_build_environment_returns_block_value
|
2013-08-19 12:32:59 -05:00
|
|
|
assert_equal 1, @env.with_build_environment { 1 }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_with_build_environment_does_not_mutate_interface
|
|
|
|
expected = @env.methods
|
|
|
|
@env.with_build_environment { assert_equal expected, @env.methods }
|
|
|
|
assert_equal expected, @env.methods
|
2013-01-22 04:32:26 -06:00
|
|
|
end
|
2013-08-19 17:21:14 -05:00
|
|
|
|
2013-08-26 15:02:51 -05:00
|
|
|
def test_append_existing_key
|
|
|
|
@env['foo'] = 'bar'
|
|
|
|
@env.append 'foo', '1'
|
|
|
|
assert_equal 'bar 1', @env['foo']
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_append_existing_key_empty
|
|
|
|
@env['foo'] = ''
|
|
|
|
@env.append 'foo', '1'
|
|
|
|
assert_equal '1', @env['foo']
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_append_missing_key
|
|
|
|
@env.append 'foo', '1'
|
|
|
|
assert_equal '1', @env['foo']
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_prepend_existing_key
|
|
|
|
@env['foo'] = 'bar'
|
|
|
|
@env.prepend 'foo', '1'
|
|
|
|
assert_equal '1 bar', @env['foo']
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_prepend_existing_key_empty
|
|
|
|
@env['foo'] = ''
|
|
|
|
@env.prepend 'foo', '1'
|
|
|
|
assert_equal '1', @env['foo']
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_prepend_missing_key
|
|
|
|
@env.prepend 'foo', '1'
|
|
|
|
assert_equal '1', @env['foo']
|
|
|
|
end
|
|
|
|
|
|
|
|
# NOTE: this may be a wrong behavior; we should probably reject objects that
|
|
|
|
# do not respond to #to_str. For now this documents existing behavior.
|
|
|
|
def test_append_coerces_value_to_string
|
|
|
|
@env.append 'foo', 42
|
|
|
|
assert_equal '42', @env['foo']
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_prepend_coerces_value_to_string
|
|
|
|
@env.prepend 'foo', 42
|
|
|
|
assert_equal '42', @env['foo']
|
|
|
|
end
|
|
|
|
|
2013-08-19 17:21:14 -05:00
|
|
|
def test_append_path
|
|
|
|
@env.append_path 'FOO', '/usr/bin'
|
|
|
|
assert_equal '/usr/bin', @env['FOO']
|
|
|
|
@env.append_path 'FOO', '/bin'
|
|
|
|
assert_equal "/usr/bin#{File::PATH_SEPARATOR}/bin", @env['FOO']
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_prepend_path
|
|
|
|
@env.prepend_path 'FOO', '/usr/bin'
|
|
|
|
assert_equal '/usr/bin', @env['FOO']
|
|
|
|
@env.prepend_path 'FOO', '/bin'
|
|
|
|
assert_equal "/bin#{File::PATH_SEPARATOR}/usr/bin", @env['FOO']
|
|
|
|
end
|
2010-03-20 23:13:25 -07:00
|
|
|
end
|