PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Library/Homebrew/test/test_ENV.rb

https://github.com/ws/homebrew
Ruby | 150 lines | 123 code | 25 blank | 2 comment | 0 complexity | 2c3d2c1e05842f2bff148293bf3907a9 MD5 | raw file
  1. require 'testing_env'
  2. require 'extend/ENV'
  3. class EnvironmentTests < Test::Unit::TestCase
  4. def setup
  5. @env = {}.extend(EnvActivation)
  6. @env.activate_extensions!
  7. end
  8. def test_switching_compilers
  9. @env.llvm
  10. @env.clang
  11. assert_nil @env['LD']
  12. assert_equal @env['OBJC'], @env['CC']
  13. end
  14. def test_with_build_environment_restores_env
  15. before = @env.dup
  16. @env.with_build_environment do
  17. @env['foo'] = 'bar'
  18. end
  19. assert_nil @env['foo']
  20. assert_equal before, @env
  21. end
  22. def test_with_build_environment_ensures_env_restored
  23. before = @env.dup
  24. begin
  25. @env.with_build_environment do
  26. @env['foo'] = 'bar'
  27. raise Exception
  28. end
  29. rescue Exception
  30. end
  31. assert_nil @env['foo']
  32. assert_equal before, @env
  33. end
  34. def test_with_build_environment_returns_block_value
  35. assert_equal 1, @env.with_build_environment { 1 }
  36. end
  37. def test_with_build_environment_does_not_mutate_interface
  38. expected = @env.methods
  39. @env.with_build_environment { assert_equal expected, @env.methods }
  40. assert_equal expected, @env.methods
  41. end
  42. def test_append_existing_key
  43. @env['foo'] = 'bar'
  44. @env.append 'foo', '1'
  45. assert_equal 'bar 1', @env['foo']
  46. end
  47. def test_append_existing_key_empty
  48. @env['foo'] = ''
  49. @env.append 'foo', '1'
  50. assert_equal '1', @env['foo']
  51. end
  52. def test_append_missing_key
  53. @env.append 'foo', '1'
  54. assert_equal '1', @env['foo']
  55. end
  56. def test_prepend_existing_key
  57. @env['foo'] = 'bar'
  58. @env.prepend 'foo', '1'
  59. assert_equal '1 bar', @env['foo']
  60. end
  61. def test_prepend_existing_key_empty
  62. @env['foo'] = ''
  63. @env.prepend 'foo', '1'
  64. assert_equal '1', @env['foo']
  65. end
  66. def test_prepend_missing_key
  67. @env.prepend 'foo', '1'
  68. assert_equal '1', @env['foo']
  69. end
  70. # NOTE: this may be a wrong behavior; we should probably reject objects that
  71. # do not respond to #to_str. For now this documents existing behavior.
  72. def test_append_coerces_value_to_string
  73. @env.append 'foo', 42
  74. assert_equal '42', @env['foo']
  75. end
  76. def test_prepend_coerces_value_to_string
  77. @env.prepend 'foo', 42
  78. assert_equal '42', @env['foo']
  79. end
  80. def test_append_path
  81. @env.append_path 'FOO', '/usr/bin'
  82. assert_equal '/usr/bin', @env['FOO']
  83. @env.append_path 'FOO', '/bin'
  84. assert_equal "/usr/bin#{File::PATH_SEPARATOR}/bin", @env['FOO']
  85. end
  86. def test_prepend_path
  87. @env.prepend_path 'FOO', '/usr/bin'
  88. assert_equal '/usr/bin', @env['FOO']
  89. @env.prepend_path 'FOO', '/bin'
  90. assert_equal "/bin#{File::PATH_SEPARATOR}/usr/bin", @env['FOO']
  91. end
  92. end
  93. module SharedEnvTests
  94. def test_switching_compilers_updates_compiler
  95. [:clang, :llvm, :gcc, :gcc_4_0].each do |compiler|
  96. @env.send(compiler)
  97. assert_equal compiler, @env.compiler
  98. end
  99. end
  100. end
  101. class StdenvTests < Test::Unit::TestCase
  102. include SharedEnvTests
  103. def setup
  104. @env = {}.extend(Stdenv)
  105. end
  106. end
  107. class SuperenvTests < Test::Unit::TestCase
  108. include SharedEnvTests
  109. attr_reader :env, :bin
  110. def setup
  111. @env = {}.extend(Superenv)
  112. @bin = HOMEBREW_REPOSITORY/"Library/ENV/#{MacOS::Xcode.version}"
  113. bin.mkpath
  114. end
  115. def test_bin
  116. assert_equal bin, Superenv.bin
  117. end
  118. def test_initializes_deps
  119. assert_equal [], env.deps
  120. assert_equal [], env.keg_only_deps
  121. end
  122. def teardown
  123. bin.rmtree
  124. end
  125. end