| 
									
										
										
										
											2013-04-08 00:55:44 -05:00
										 |  |  | require 'testing_env' | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  | require 'software_spec' | 
					
						
							| 
									
										
										
										
											2013-04-08 00:55:44 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class SoftwareSpecTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:40 -05:00
										 |  |  |   def setup | 
					
						
							|  |  |  |     @spec = SoftwareSpec.new | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_resource | 
					
						
							|  |  |  |     @spec.resource('foo') { url 'foo-1.0' } | 
					
						
							| 
									
										
										
										
											2014-07-30 18:56:37 -05:00
										 |  |  |     assert @spec.resource_defined?("foo") | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:40 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_raises_when_duplicate_resources_are_defined | 
					
						
							|  |  |  |     @spec.resource('foo') { url 'foo-1.0' } | 
					
						
							|  |  |  |     assert_raises(DuplicateResourceError) do | 
					
						
							|  |  |  |       @spec.resource('foo') { url 'foo-1.0' } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_raises_when_accessing_missing_resources | 
					
						
							| 
									
										
										
										
											2014-09-14 11:18:55 -05:00
										 |  |  |     @spec.owner = Class.new { def name; "test"; end }.new | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:40 -05:00
										 |  |  |     assert_raises(ResourceMissingError) { @spec.resource('foo') } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 14:50:22 -06:00
										 |  |  |   def test_set_owner | 
					
						
							|  |  |  |     owner = stub(:name => 'some_name') | 
					
						
							|  |  |  |     @spec.owner = owner | 
					
						
							|  |  |  |     assert_equal owner, @spec.owner | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:40 -05:00
										 |  |  |   def test_resource_owner | 
					
						
							|  |  |  |     @spec.resource('foo') { url 'foo-1.0' } | 
					
						
							| 
									
										
										
										
											2013-09-23 21:39:19 -05:00
										 |  |  |     @spec.owner = stub(:name => 'some_name') | 
					
						
							|  |  |  |     assert_equal 'some_name', @spec.name | 
					
						
							|  |  |  |     @spec.resources.each_value { |r| assert_equal @spec, r.owner } | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:40 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-26 23:31:27 -06:00
										 |  |  |   def test_resource_without_version_receives_owners_version | 
					
						
							|  |  |  |     @spec.url('foo-42') | 
					
						
							|  |  |  |     @spec.resource('bar') { url 'bar' } | 
					
						
							|  |  |  |     @spec.owner = stub(:name => 'some_name') | 
					
						
							|  |  |  |     assert_version_equal '42', @spec.resource('bar').version | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |   def test_option | 
					
						
							|  |  |  |     @spec.option('foo') | 
					
						
							| 
									
										
										
										
											2014-07-31 19:37:39 -05:00
										 |  |  |     assert @spec.option_defined?("foo") | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_option_raises_when_begins_with_dashes | 
					
						
							| 
									
										
										
										
											2014-08-07 00:48:13 -05:00
										 |  |  |     assert_raises(ArgumentError) { @spec.option("--foo") } | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_option_raises_when_name_empty | 
					
						
							| 
									
										
										
										
											2014-08-07 00:48:13 -05:00
										 |  |  |     assert_raises(ArgumentError) { @spec.option("") } | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-07 00:03:25 -05:00
										 |  |  |   def test_cxx11_option_special_case | 
					
						
							|  |  |  |     @spec.option(:cxx11) | 
					
						
							|  |  |  |     assert @spec.option_defined?("c++11") | 
					
						
							|  |  |  |     refute @spec.option_defined?("cxx11") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-07 00:48:13 -05:00
										 |  |  |   def test_option_description | 
					
						
							|  |  |  |     @spec.option("bar", "description") | 
					
						
							|  |  |  |     assert_equal "description", @spec.options.first.description | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_option_description_defaults_to_empty_string | 
					
						
							|  |  |  |     @spec.option("foo") | 
					
						
							|  |  |  |     assert_equal "", @spec.options.first.description | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-16 13:00:20 +01:00
										 |  |  |   def test_deprecated_option | 
					
						
							|  |  |  |     @spec.deprecated_option('foo' => 'bar') | 
					
						
							| 
									
										
										
										
											2014-12-01 11:22:58 -05:00
										 |  |  |     refute_empty @spec.deprecated_options | 
					
						
							| 
									
										
										
										
											2014-10-16 13:00:20 +01:00
										 |  |  |     assert_equal "foo", @spec.deprecated_options.first.old | 
					
						
							|  |  |  |     assert_equal "bar", @spec.deprecated_options.first.current | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_deprecated_options | 
					
						
							|  |  |  |     @spec.deprecated_option(['foo1', 'foo2'] => 'bar1', 'foo3' => ['bar2', 'bar3']) | 
					
						
							| 
									
										
										
										
											2014-10-16 13:01:05 +01:00
										 |  |  |     assert_includes @spec.deprecated_options, DeprecatedOption.new("foo1", "bar1") | 
					
						
							|  |  |  |     assert_includes @spec.deprecated_options, DeprecatedOption.new("foo2", "bar1") | 
					
						
							|  |  |  |     assert_includes @spec.deprecated_options, DeprecatedOption.new("foo3", "bar2") | 
					
						
							|  |  |  |     assert_includes @spec.deprecated_options, DeprecatedOption.new("foo3", "bar3") | 
					
						
							| 
									
										
										
										
											2014-10-16 13:00:20 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_deprecated_option_raises_when_empty | 
					
						
							|  |  |  |     assert_raises(ArgumentError) { @spec.deprecated_option({}) } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |   def test_depends_on | 
					
						
							|  |  |  |     @spec.depends_on('foo') | 
					
						
							|  |  |  |     assert_equal 'foo', @spec.deps.first.name | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_dependency_option_integration | 
					
						
							|  |  |  |     @spec.depends_on 'foo' => :optional | 
					
						
							|  |  |  |     @spec.depends_on 'bar' => :recommended | 
					
						
							| 
									
										
										
										
											2014-07-31 19:37:39 -05:00
										 |  |  |     assert @spec.option_defined?("with-foo") | 
					
						
							|  |  |  |     assert @spec.option_defined?("without-bar") | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_explicit_options_override_default_dep_option_description | 
					
						
							|  |  |  |     @spec.option('with-foo', 'blah') | 
					
						
							|  |  |  |     @spec.depends_on('foo' => :optional) | 
					
						
							| 
									
										
										
										
											2014-07-31 19:37:39 -05:00
										 |  |  |     assert_equal "blah", @spec.options.first.description | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_patch | 
					
						
							|  |  |  |     @spec.patch :p1, :DATA | 
					
						
							|  |  |  |     assert_equal 1, @spec.patches.length | 
					
						
							|  |  |  |     assert_equal :p1, @spec.patches.first.strip | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:40 -05:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class HeadSoftwareSpecTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2013-04-08 00:55:44 -05:00
										 |  |  |   def setup | 
					
						
							|  |  |  |     @spec = HeadSoftwareSpec.new | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_version | 
					
						
							|  |  |  |     assert_version_equal 'HEAD', @spec.version | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_verify_download_integrity | 
					
						
							|  |  |  |     assert_nil @spec.verify_download_integrity(Object.new) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class BottleSpecificationTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2013-04-08 00:55:44 -05:00
										 |  |  |   def setup | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |     @spec = BottleSpecification.new | 
					
						
							| 
									
										
										
										
											2013-04-08 00:55:44 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_checksum_setters | 
					
						
							|  |  |  |     checksums = { | 
					
						
							|  |  |  |       :snow_leopard_32 => 'deadbeef'*5, | 
					
						
							|  |  |  |       :snow_leopard    => 'faceb00c'*5, | 
					
						
							|  |  |  |       :lion            => 'baadf00d'*5, | 
					
						
							|  |  |  |       :mountain_lion   => '8badf00d'*5, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     checksums.each_pair do |cat, sha1| | 
					
						
							|  |  |  |       @spec.sha1(sha1 => cat) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     checksums.each_pair do |cat, sha1| | 
					
						
							| 
									
										
										
										
											2014-07-13 13:06:35 -05:00
										 |  |  |       checksum, _ = @spec.checksum_for(cat) | 
					
						
							|  |  |  |       assert_equal Checksum.new(:sha1, sha1), checksum | 
					
						
							| 
									
										
										
										
											2013-04-08 00:55:44 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_other_setters | 
					
						
							|  |  |  |     double = Object.new | 
					
						
							|  |  |  |     %w{root_url prefix cellar revision}.each do |method| | 
					
						
							|  |  |  |       @spec.send(method, double) | 
					
						
							|  |  |  |       assert_equal double, @spec.send(method) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |