| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  | require "software_spec" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe SoftwareSpec do | 
					
						
							| 
									
										
										
										
											2017-05-09 23:00:51 +02:00
										 |  |  |   alias_matcher :have_defined_resource, :be_resource_defined | 
					
						
							|  |  |  |   alias_matcher :have_defined_option, :be_option_defined | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |   subject(:spec) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |   let(:owner) { double(name: "some_name", full_name: "some_name", tap: "homebrew/core") } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#resource" do | 
					
						
							|  |  |  |     it "defines a resource" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.resource("foo") { url "foo-1.0" } | 
					
						
							|  |  |  |       expect(spec).to have_defined_resource("foo") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "sets itself to be the resource's owner" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.resource("foo") { url "foo-1.0" } | 
					
						
							|  |  |  |       spec.owner = owner | 
					
						
							|  |  |  |       spec.resources.each_value do |r| | 
					
						
							|  |  |  |         expect(r.owner).to eq(spec) | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "receives the owner's version if it has no own version" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.url("foo-42") | 
					
						
							|  |  |  |       spec.resource("bar") { url "bar" } | 
					
						
							|  |  |  |       spec.owner = owner | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(spec.resource("bar").version).to eq("42") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error when duplicate resources are defined" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.resource("foo") { url "foo-1.0" } | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |       expect { | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         spec.resource("foo") { url "foo-1.0" } | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |       }.to raise_error(DuplicateResourceError) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error when accessing missing resources" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.owner = owner | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |       expect { | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         spec.resource("foo") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |       }.to raise_error(ResourceMissingError) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#owner" do | 
					
						
							|  |  |  |     it "sets the owner" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.owner = owner | 
					
						
							|  |  |  |       expect(spec.owner).to eq(owner) | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "sets the name" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.owner = owner | 
					
						
							|  |  |  |       expect(spec.name).to eq(owner.name) | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#option" do | 
					
						
							|  |  |  |     it "defines an option" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.option("foo") | 
					
						
							|  |  |  |       expect(spec).to have_defined_option("foo") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error when it begins with dashes" do | 
					
						
							|  |  |  |       expect { | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         spec.option("--foo") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |       }.to raise_error(ArgumentError) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error when name is empty" do | 
					
						
							|  |  |  |       expect { | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         spec.option("") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |       }.to raise_error(ArgumentError) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "special cases the cxx11 option" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.option(:cxx11) | 
					
						
							|  |  |  |       expect(spec).to have_defined_option("c++11") | 
					
						
							|  |  |  |       expect(spec).not_to have_defined_option("cxx11") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "supports options with descriptions" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.option("bar", "description") | 
					
						
							|  |  |  |       expect(spec.options.first.description).to eq("description") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "defaults to an empty string when no description is given" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.option("foo") | 
					
						
							|  |  |  |       expect(spec.options.first.description).to eq("") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#deprecated_option" do | 
					
						
							|  |  |  |     it "allows specifying deprecated options" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.deprecated_option("foo" => "bar") | 
					
						
							|  |  |  |       expect(spec.deprecated_options).not_to be_empty | 
					
						
							|  |  |  |       expect(spec.deprecated_options.first.old).to eq("foo") | 
					
						
							|  |  |  |       expect(spec.deprecated_options.first.current).to eq("bar") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "allows specifying deprecated options as a Hash from an Array/String to an Array/String" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.deprecated_option(["foo1", "foo2"] => "bar1", "foo3" => ["bar2", "bar3"]) | 
					
						
							|  |  |  |       expect(spec.deprecated_options).to include(DeprecatedOption.new("foo1", "bar1")) | 
					
						
							|  |  |  |       expect(spec.deprecated_options).to include(DeprecatedOption.new("foo2", "bar1")) | 
					
						
							|  |  |  |       expect(spec.deprecated_options).to include(DeprecatedOption.new("foo3", "bar2")) | 
					
						
							|  |  |  |       expect(spec.deprecated_options).to include(DeprecatedOption.new("foo3", "bar3")) | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error when empty" do | 
					
						
							|  |  |  |       expect { | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         spec.deprecated_option({}) | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |       }.to raise_error(ArgumentError) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#depends_on" do | 
					
						
							|  |  |  |     it "allows specifying dependencies" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.depends_on("foo") | 
					
						
							|  |  |  |       expect(spec.deps.first.name).to eq("foo") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "allows specifying optional dependencies" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.depends_on "foo" => :optional | 
					
						
							|  |  |  |       expect(spec).to have_defined_option("with-foo") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "allows specifying recommended dependencies" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.depends_on "bar" => :recommended | 
					
						
							|  |  |  |       expect(spec).to have_defined_option("without-bar") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-29 15:50:17 -03:00
										 |  |  |   describe "#uses_from_macos" do | 
					
						
							|  |  |  |     it "allows specifying dependencies", :needs_linux do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.uses_from_macos("foo") | 
					
						
							| 
									
										
										
										
											2019-05-29 15:50:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(spec.deps.first.name).to eq("foo") | 
					
						
							| 
									
										
										
										
											2019-05-29 15:50:17 -03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "works with tags", :needs_linux do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.uses_from_macos("foo" => :build) | 
					
						
							| 
									
										
										
										
											2019-05-29 15:50:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(spec.deps.first.name).to eq("foo") | 
					
						
							|  |  |  |       expect(spec.deps.first.tags).to include(:build) | 
					
						
							| 
									
										
										
										
											2019-05-29 15:50:17 -03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "ignores OS version specifications", :needs_linux do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.uses_from_macos("foo", since: :mojave) | 
					
						
							|  |  |  |       spec.uses_from_macos("bar" => :build, :since => :mojave) | 
					
						
							| 
									
										
										
										
											2019-05-29 15:50:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(spec.deps.first.name).to eq("foo") | 
					
						
							|  |  |  |       expect(spec.deps.last.name).to eq("bar") | 
					
						
							|  |  |  |       expect(spec.deps.last.tags).to include(:build) | 
					
						
							| 
									
										
										
										
											2019-05-29 15:50:17 -03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |   specify "explicit options override defaupt depends_on option description" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |     spec.option("with-foo", "blah") | 
					
						
							|  |  |  |     spec.depends_on("foo" => :optional) | 
					
						
							|  |  |  |     expect(spec.options.first.description).to eq("blah") | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#patch" do | 
					
						
							|  |  |  |     it "adds a patch" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       spec.patch(:p1, :DATA) | 
					
						
							|  |  |  |       expect(spec.patches.count).to eq(1) | 
					
						
							|  |  |  |       expect(spec.patches.first.strip).to eq(:p1) | 
					
						
							| 
									
										
										
										
											2017-02-20 23:28:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |