| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "testing_env" | 
					
						
							|  |  |  | require "extend/ENV" | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-17 20:04:21 -04:00
										 |  |  | module SharedEnvTests | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   def setup | 
					
						
							|  |  |  |     @env = {}.extend(EnvActivation) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-21 12:01:19 -05:00
										 |  |  |   def test_switching_compilers | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     @env.clang | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       @env["foo"] = "bar" | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:57 -06:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_nil @env["foo"] | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |         @env["foo"] = "bar" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |         raise Exception | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-01-22 04:32:26 -06:00
										 |  |  |     rescue Exception | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_nil @env["foo"] | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @env["foo"] = "bar" | 
					
						
							|  |  |  |     @env.append "foo", "1" | 
					
						
							|  |  |  |     assert_equal "bar 1", @env["foo"] | 
					
						
							| 
									
										
										
										
											2013-08-26 15:02:51 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_append_existing_key_empty | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @env["foo"] = "" | 
					
						
							|  |  |  |     @env.append "foo", "1" | 
					
						
							|  |  |  |     assert_equal "1", @env["foo"] | 
					
						
							| 
									
										
										
										
											2013-08-26 15:02:51 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_append_missing_key | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @env.append "foo", "1" | 
					
						
							|  |  |  |     assert_equal "1", @env["foo"] | 
					
						
							| 
									
										
										
										
											2013-08-26 15:02:51 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_prepend_existing_key | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @env["foo"] = "bar" | 
					
						
							|  |  |  |     @env.prepend "foo", "1" | 
					
						
							|  |  |  |     assert_equal "1 bar", @env["foo"] | 
					
						
							| 
									
										
										
										
											2013-08-26 15:02:51 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_prepend_existing_key_empty | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @env["foo"] = "" | 
					
						
							|  |  |  |     @env.prepend "foo", "1" | 
					
						
							|  |  |  |     assert_equal "1", @env["foo"] | 
					
						
							| 
									
										
										
										
											2013-08-26 15:02:51 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_prepend_missing_key | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @env.prepend "foo", "1" | 
					
						
							|  |  |  |     assert_equal "1", @env["foo"] | 
					
						
							| 
									
										
										
										
											2013-08-26 15:02:51 -05:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @env.append "foo", 42
 | 
					
						
							|  |  |  |     assert_equal "42", @env["foo"] | 
					
						
							| 
									
										
										
										
											2013-08-26 15:02:51 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_prepend_coerces_value_to_string | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @env.prepend "foo", 42
 | 
					
						
							|  |  |  |     assert_equal "42", @env["foo"] | 
					
						
							| 
									
										
										
										
											2013-08-26 15:02:51 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-19 17:21:14 -05:00
										 |  |  |   def test_append_path | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @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"] | 
					
						
							| 
									
										
										
										
											2013-08-19 17:21:14 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_prepend_path | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @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"] | 
					
						
							| 
									
										
										
										
											2013-08-19 17:21:14 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-20 22:54:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_switching_compilers_updates_compiler | 
					
						
							| 
									
										
										
										
											2016-05-22 09:40:08 +01:00
										 |  |  |     [:clang, :gcc, :gcc_4_0].each do |compiler| | 
					
						
							| 
									
										
										
										
											2013-09-20 22:54:07 -05:00
										 |  |  |       @env.send(compiler) | 
					
						
							|  |  |  |       assert_equal compiler, @env.compiler | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-04-25 02:03:00 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_deparallelize_block_form_restores_makeflags | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @env["MAKEFLAGS"] = "-j4" | 
					
						
							| 
									
										
										
										
											2015-04-25 02:03:00 -07:00
										 |  |  |     @env.deparallelize do | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       assert_nil @env["MAKEFLAGS"] | 
					
						
							| 
									
										
										
										
											2015-04-25 02:03:00 -07:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_equal "-j4", @env["MAKEFLAGS"] | 
					
						
							| 
									
										
										
										
											2015-04-25 02:03:00 -07:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-20 22:54:07 -05:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class StdenvTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2013-09-20 22:54:07 -05:00
										 |  |  |   include SharedEnvTests | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def setup | 
					
						
							| 
									
										
										
										
											2015-06-17 20:04:21 -04:00
										 |  |  |     super | 
					
						
							|  |  |  |     @env.extend(Stdenv) | 
					
						
							| 
									
										
										
										
											2013-09-20 22:54:07 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class SuperenvTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2013-09-20 22:54:07 -05:00
										 |  |  |   include SharedEnvTests | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def setup | 
					
						
							| 
									
										
										
										
											2015-06-17 20:04:21 -04:00
										 |  |  |     super | 
					
						
							|  |  |  |     @env.extend(Superenv) | 
					
						
							| 
									
										
										
										
											2013-12-12 15:42:31 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_initializes_deps | 
					
						
							| 
									
										
										
										
											2015-04-21 20:46:02 -04:00
										 |  |  |     assert_equal [], @env.deps | 
					
						
							|  |  |  |     assert_equal [], @env.keg_only_deps | 
					
						
							| 
									
										
										
										
											2013-09-20 22:54:07 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-06-16 22:15:28 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_unsupported_cxx11 | 
					
						
							|  |  |  |     %w[gcc gcc-4.7].each do |compiler| | 
					
						
							|  |  |  |       @env["HOMEBREW_CC"] = compiler | 
					
						
							|  |  |  |       assert_raises do | 
					
						
							|  |  |  |         @env.cxx11 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       refute_match "x", @env["HOMEBREW_CCCFG"] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_supported_cxx11_gcc_5 | 
					
						
							|  |  |  |     @env["HOMEBREW_CC"] = "gcc-5" | 
					
						
							|  |  |  |     @env.cxx11 | 
					
						
							|  |  |  |     assert_match "x", @env["HOMEBREW_CCCFG"] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_supported_cxx11_gcc_6 | 
					
						
							|  |  |  |     @env["HOMEBREW_CC"] = "gcc-6" | 
					
						
							|  |  |  |     @env.cxx11 | 
					
						
							|  |  |  |     assert_match "x", @env["HOMEBREW_CCCFG"] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_supported_cxx11_clang | 
					
						
							|  |  |  |     @env["HOMEBREW_CC"] = "clang" | 
					
						
							|  |  |  |     @env.cxx11 | 
					
						
							|  |  |  |     assert_match "x", @env["HOMEBREW_CCCFG"] | 
					
						
							|  |  |  |     assert_match "g", @env["HOMEBREW_CCCFG"] | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-20 22:54:07 -05:00
										 |  |  | end |