diff options
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/cmd/commands_spec.rb | 85 | ||||
| -rw-r--r-- | Library/Homebrew/test/commands_test.rb | 77 | ||||
| -rw-r--r-- | Library/Homebrew/test/formula_spec_selection_spec.rb | 100 | ||||
| -rw-r--r-- | Library/Homebrew/test/formula_spec_selection_test.rb | 99 |
4 files changed, 185 insertions, 176 deletions
diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb index f42072956..32d07a0bc 100644 --- a/Library/Homebrew/test/cmd/commands_spec.rb +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -1,3 +1,7 @@ +require "cmd/command" +require "cmd/commands" +require "fileutils" + describe "brew commands", :integration_test do it "prints a list of all available commands" do expect { brew "commands" } @@ -5,3 +9,84 @@ describe "brew commands", :integration_test do .and be_a_success end end + +RSpec.shared_context "custom internal commands" do + let(:cmds) do + [ + # internal commands + HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", + HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", + + # internal developer-commands + HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", + HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", + ] + end + + around(:each) do |example| + begin + cmds.each do |f| + FileUtils.touch f + end + + example.run + ensure + FileUtils.rm_f cmds + end + end +end + +describe Homebrew do + include_context "custom internal commands" + + specify "::internal_commands" do + cmds = described_class.internal_commands + expect(cmds).to include("rbcmd"), "Ruby commands files should be recognized" + expect(cmds).to include("shcmd"), "Shell commands files should be recognized" + expect(cmds).not_to include("rbdevcmd"), "Dev commands shouldn't be included" + end + + specify "::internal_developer_commands" do + cmds = described_class.internal_developer_commands + expect(cmds).to include("rbdevcmd"), "Ruby commands files should be recognized" + expect(cmds).to include("shdevcmd"), "Shell commands files should be recognized" + expect(cmds).not_to include("rbcmd"), "Non-dev commands shouldn't be included" + end + + specify "::external_commands" do + Dir.mktmpdir do |dir| + %w[brew-t1 brew-t2.rb brew-t3.py].each do |file| + path = "#{dir}/#{file}" + FileUtils.touch path + FileUtils.chmod 0755, path + end + + FileUtils.touch "#{dir}/brew-t4" + + ENV["PATH"] += "#{File::PATH_SEPARATOR}#{dir}" + cmds = described_class.external_commands + + expect(cmds).to include("t1"), "Executable files should be included" + expect(cmds).to include("t2"), "Executable Ruby files should be included" + expect(cmds).not_to include("t3"), "Executable files with a non Ruby extension shoudn't be included" + expect(cmds).not_to include("t4"), "Non-executable files shouldn't be included" + end + end +end + +describe Commands do + include_context "custom internal commands" + + describe "::path" do + specify "returns the path for an internal command" do + expect(described_class.path("rbcmd")).to eq(HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb") + expect(described_class.path("shcmd")).to eq(HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh") + expect(described_class.path("idontexist1234")).to be nil + end + + specify "returns the path for an internal developer-command" do + expect(described_class.path("rbdevcmd")).to eq(HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb") + expect(described_class.path("shdevcmd")).to eq(HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh") + end + end +end diff --git a/Library/Homebrew/test/commands_test.rb b/Library/Homebrew/test/commands_test.rb deleted file mode 100644 index da88ee2d5..000000000 --- a/Library/Homebrew/test/commands_test.rb +++ /dev/null @@ -1,77 +0,0 @@ -require "testing_env" -require "cmd/command" -require "cmd/commands" -require "fileutils" -require "testing_env" - -class CommandsTests < Homebrew::TestCase - def setup - super - @cmds = [ - # internal commands - HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", - HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", - - # internal development commands - HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", - HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", - ] - - @cmds.each { |f| FileUtils.touch f } - end - - def teardown - @cmds.each(&:unlink) - super - end - - def test_internal_commands - cmds = Homebrew.internal_commands - assert cmds.include?("rbcmd"), "Ruby commands files should be recognized" - assert cmds.include?("shcmd"), "Shell commands files should be recognized" - refute cmds.include?("rbdevcmd"), "Dev commands shouldn't be included" - end - - def test_internal_developer_commands - cmds = Homebrew.internal_developer_commands - assert cmds.include?("rbdevcmd"), "Ruby commands files should be recognized" - assert cmds.include?("shdevcmd"), "Shell commands files should be recognized" - refute cmds.include?("rbcmd"), "Non-dev commands shouldn't be included" - end - - def test_external_commands - mktmpdir do |dir| - %w[brew-t1 brew-t2.rb brew-t3.py].each do |file| - path = "#{dir}/#{file}" - FileUtils.touch path - FileUtils.chmod 0755, path - end - - FileUtils.touch "#{dir}/brew-t4" - - ENV["PATH"] += "#{File::PATH_SEPARATOR}#{dir}" - cmds = Homebrew.external_commands - - assert cmds.include?("t1"), "Executable files should be included" - assert cmds.include?("t2"), "Executable Ruby files should be included" - refute cmds.include?("t3"), - "Executable files with a non Ruby extension shoudn't be included" - refute cmds.include?("t4"), "Non-executable files shouldn't be included" - end - end - - def test_internal_command_path - assert_equal HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", - Commands.path("rbcmd") - assert_equal HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", - Commands.path("shcmd") - assert_nil Commands.path("idontexist1234") - end - - def test_internal_dev_command_path - assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", - Commands.path("rbdevcmd") - assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", - Commands.path("shdevcmd") - end -end diff --git a/Library/Homebrew/test/formula_spec_selection_spec.rb b/Library/Homebrew/test/formula_spec_selection_spec.rb new file mode 100644 index 000000000..20231ffda --- /dev/null +++ b/Library/Homebrew/test/formula_spec_selection_spec.rb @@ -0,0 +1,100 @@ +require "formula" + +describe Formula do + describe "::new" do + it "selects stable by default" do + f = formula do + url "foo-1.0" + devel { url "foo-1.1a" } + head "foo" + end + + expect(f).to be_stable + end + + it "selects stable when exclusive" do + f = formula { url "foo-1.0" } + expect(f).to be_stable + end + + it "selects devel before HEAD" do + f = formula do + devel { url "foo-1.1a" } + head "foo" + end + + expect(f).to be_devel + end + + it "selects devel when exclusive" do + f = formula { devel { url "foo-1.1a" } } + expect(f).to be_devel + end + + it "selects HEAD when exclusive" do + f = formula { head "foo" } + expect(f).to be_head + end + + it "does not select an incomplete spec" do + f = formula do + sha256 TEST_SHA256 + version "1.0" + head "foo" + end + + expect(f).to be_head + end + + it "does not set an incomplete stable spec" do + f = formula do + sha256 TEST_SHA256 + devel { url "foo-1.1a" } + head "foo" + end + + expect(f.stable).to be nil + expect(f).to be_devel + end + + it "selects HEAD when requested" do + f = formula("test", spec: :head) do + url "foo-1.0" + devel { url "foo-1.1a" } + head "foo" + end + + expect(f).to be_head + end + + it "selects devel when requested" do + f = formula("test", spec: :devel) do + url "foo-1.0" + devel { url "foo-1.1a" } + head "foo" + end + + expect(f).to be_devel + end + + it "does not set an incomplete devel spec" do + f = formula do + url "foo-1.0" + devel { version "1.1a" } + head "foo" + end + + expect(f.devel).to be nil + expect(f).to be_stable + end + + it "does not raise an error for a missing spec" do + f = formula("test", spec: :devel) do + url "foo-1.0" + head "foo" + end + + expect(f).to be_stable + end + end +end diff --git a/Library/Homebrew/test/formula_spec_selection_test.rb b/Library/Homebrew/test/formula_spec_selection_test.rb deleted file mode 100644 index 7148df173..000000000 --- a/Library/Homebrew/test/formula_spec_selection_test.rb +++ /dev/null @@ -1,99 +0,0 @@ -require "testing_env" -require "formula" - -class FormulaSpecSelectionTests < Homebrew::TestCase - def test_selects_stable_by_default - f = formula do - url "foo-1.0" - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :stable? - end - - def test_selects_stable_when_exclusive - f = formula { url "foo-1.0" } - assert_predicate f, :stable? - end - - def test_selects_devel_before_head - f = formula do - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :devel? - end - - def test_selects_devel_when_exclusive - f = formula { devel { url "foo-1.1a" } } - assert_predicate f, :devel? - end - - def test_selects_head_when_exclusive - f = formula { head "foo" } - assert_predicate f, :head? - end - - def test_incomplete_spec_not_selected - f = formula do - sha256 TEST_SHA256 - version "1.0" - head "foo" - end - - assert_predicate f, :head? - end - - def test_incomplete_stable_not_set - f = formula do - sha256 TEST_SHA256 - devel { url "foo-1.1a" } - head "foo" - end - - assert_nil f.stable - assert_predicate f, :devel? - end - - def test_selects_head_when_requested - f = formula("test", Pathname.new(__FILE__).expand_path, :head) do - url "foo-1.0" - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :head? - end - - def test_selects_devel_when_requested - f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do - url "foo-1.0" - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :devel? - end - - def test_incomplete_devel_not_set - f = formula do - url "foo-1.0" - devel { version "1.1a" } - head "foo" - end - - assert_nil f.devel - assert_predicate f, :stable? - end - - def test_does_not_raise_for_missing_spec - f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do - url "foo-1.0" - head "foo" - end - - assert_predicate f, :stable? - end -end |
