| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "testing_env" | 
					
						
							|  |  |  | require "requirement" | 
					
						
							| 
									
										
										
										
											2013-01-13 20:05:09 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class RequirementTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2015-12-14 19:39:49 +00:00
										 |  |  |   class TestRequirement < Requirement; end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-13 20:05:09 -06:00
										 |  |  |   def test_accepts_single_tag | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     dep = Requirement.new(%w[bar]) | 
					
						
							|  |  |  |     assert_equal %w[bar], dep.tags | 
					
						
							| 
									
										
										
										
											2013-01-13 20:05:09 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_accepts_multiple_tags | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     dep = Requirement.new(%w[bar baz]) | 
					
						
							|  |  |  |     assert_equal %w[bar baz].sort, dep.tags.sort | 
					
						
							| 
									
										
										
										
											2013-01-13 20:05:09 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-14 19:47:19 +00:00
										 |  |  |   def test_option_names | 
					
						
							| 
									
										
										
										
											2015-12-14 19:39:49 +00:00
										 |  |  |     dep = TestRequirement.new | 
					
						
							| 
									
										
										
										
											2015-12-14 19:47:19 +00:00
										 |  |  |     assert_equal %w[test], dep.option_names | 
					
						
							| 
									
										
										
										
											2015-12-14 19:39:49 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-13 20:05:09 -06:00
										 |  |  |   def test_preserves_symbol_tags | 
					
						
							| 
									
										
										
										
											2013-05-06 16:08:50 -05:00
										 |  |  |     dep = Requirement.new([:build]) | 
					
						
							| 
									
										
										
										
											2013-01-13 20:05:09 -06:00
										 |  |  |     assert_equal [:build], dep.tags | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_accepts_symbol_and_string_tags | 
					
						
							|  |  |  |     dep = Requirement.new([:build, "bar"]) | 
					
						
							|  |  |  |     assert_equal [:build, "bar"], dep.tags | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-15 18:39:19 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_dsl_fatal | 
					
						
							|  |  |  |     req = Class.new(Requirement) { fatal true }.new | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     assert_predicate req, :fatal? | 
					
						
							| 
									
										
										
										
											2013-01-15 18:39:19 -06:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_satisfy_true | 
					
						
							|  |  |  |     req = Class.new(Requirement) do | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |       satisfy(build_env: false) { true } | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |     end.new | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     assert_predicate req, :satisfied? | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_satisfy_false | 
					
						
							|  |  |  |     req = Class.new(Requirement) do | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |       satisfy(build_env: false) { false } | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |     end.new | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     refute_predicate req, :satisfied? | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-22 14:11:21 -06:00
										 |  |  |   def test_satisfy_with_boolean | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |     req = Class.new(Requirement) do | 
					
						
							| 
									
										
										
										
											2013-01-22 14:11:21 -06:00
										 |  |  |       satisfy true | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |     end.new | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     assert_predicate req, :satisfied? | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-22 14:11:21 -06:00
										 |  |  |   def test_satisfy_sets_up_build_env_by_default | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |     req = Class.new(Requirement) do | 
					
						
							| 
									
										
										
										
											2013-01-22 14:11:21 -06:00
										 |  |  |       satisfy { true } | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |     end.new | 
					
						
							| 
									
										
										
										
											2013-01-22 14:11:21 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ENV.expects(:with_build_environment).yields.returns(true) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     assert_predicate req, :satisfied? | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-22 14:11:21 -06:00
										 |  |  |   def test_satisfy_build_env_can_be_disabled | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |     req = Class.new(Requirement) do | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |       satisfy(build_env: false) { true } | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |     end.new | 
					
						
							| 
									
										
										
										
											2013-01-22 14:11:21 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ENV.expects(:with_build_environment).never | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     assert_predicate req, :satisfied? | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-22 14:33:33 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_infers_path_from_satisfy_result | 
					
						
							|  |  |  |     which_path = Pathname.new("/foo/bar/baz") | 
					
						
							|  |  |  |     req = Class.new(Requirement) do | 
					
						
							|  |  |  |       satisfy { which_path } | 
					
						
							|  |  |  |     end.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ENV.expects(:with_build_environment).yields.returns(which_path) | 
					
						
							| 
									
										
										
										
											2013-08-19 17:21:13 -05:00
										 |  |  |     ENV.expects(:append_path).with("PATH", which_path.parent) | 
					
						
							| 
									
										
										
										
											2013-01-22 14:33:33 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-24 10:39:00 -05:00
										 |  |  |     req.satisfied? | 
					
						
							| 
									
										
										
										
											2013-01-22 14:33:33 -06:00
										 |  |  |     req.modify_build_environment | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:30 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_dsl_build | 
					
						
							|  |  |  |     req = Class.new(Requirement) { build true }.new | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     assert_predicate req, :build? | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:30 -06:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-02-12 16:24:30 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_infer_name_from_class | 
					
						
							| 
									
										
										
										
											2014-06-12 16:09:03 -05:00
										 |  |  |     const = :FooRequirement | 
					
						
							|  |  |  |     klass = self.class | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-12 16:24:30 -06:00
										 |  |  |     klass.const_set(const, Class.new(Requirement)) | 
					
						
							| 
									
										
										
										
											2014-06-12 16:09:03 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     begin | 
					
						
							|  |  |  |       assert_equal "foo", klass.const_get(const).new.name | 
					
						
							|  |  |  |     ensure | 
					
						
							|  |  |  |       klass.send(:remove_const, const) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-02-12 16:24:30 -06:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-06-03 15:08:47 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_dsl_default_formula | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     req = Class.new(Requirement) { default_formula "foo" }.new | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     assert_predicate req, :default_formula? | 
					
						
							| 
									
										
										
										
											2013-06-03 15:08:47 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_to_dependency | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     req = Class.new(Requirement) { default_formula "foo" }.new | 
					
						
							|  |  |  |     assert_equal Dependency.new("foo"), req.to_dependency | 
					
						
							| 
									
										
										
										
											2013-06-03 15:08:47 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_to_dependency_calls_requirement_modify_build_environment | 
					
						
							|  |  |  |     error = Class.new(StandardError) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     req = Class.new(Requirement) do | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       default_formula "foo" | 
					
						
							| 
									
										
										
										
											2013-06-03 15:08:47 -05:00
										 |  |  |       satisfy { true } | 
					
						
							|  |  |  |       env { raise error } | 
					
						
							|  |  |  |     end.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_raises(error) do | 
					
						
							|  |  |  |       req.to_dependency.modify_build_environment | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-06-27 01:18:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-07 21:32:35 -05:00
										 |  |  |   def test_modify_build_environment_without_env_proc | 
					
						
							|  |  |  |     assert_nil Class.new(Requirement).new.modify_build_environment | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-27 01:18:32 -05:00
										 |  |  |   def test_eql | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     a = Requirement.new | 
					
						
							|  |  |  |     b = Requirement.new | 
					
						
							| 
									
										
										
										
											2014-11-12 17:35:16 -06:00
										 |  |  |     assert_equal a, b | 
					
						
							| 
									
										
										
										
											2014-07-03 16:54:46 -05:00
										 |  |  |     assert_eql a, b | 
					
						
							| 
									
										
										
										
											2013-06-27 01:18:32 -05:00
										 |  |  |     assert_equal a.hash, b.hash | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_not_eql | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     a = Requirement.new([:optional]) | 
					
						
							|  |  |  |     b = Requirement.new | 
					
						
							| 
									
										
										
										
											2014-11-12 17:35:16 -06:00
										 |  |  |     refute_equal a, b | 
					
						
							| 
									
										
										
										
											2014-07-03 16:54:46 -05:00
										 |  |  |     refute_eql a, b | 
					
						
							| 
									
										
										
										
											2014-06-10 22:43:47 -05:00
										 |  |  |     refute_equal a.hash, b.hash | 
					
						
							| 
									
										
										
										
											2013-06-27 01:18:32 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-13 20:05:09 -06:00
										 |  |  | end |