tap: add tests for formula_file? and cask_file?
This commit is contained in:
		
							parent
							
								
									cd430c4d34
								
							
						
					
					
						commit
						62a4734c90
					
				@ -755,13 +755,15 @@ class Tap
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  sig { returns(Regexp) }
 | 
					  sig { returns(Regexp) }
 | 
				
			||||||
  def formula_file_regex
 | 
					  def formula_file_regex
 | 
				
			||||||
    @formula_file_regex ||= case formula_dir.basename.to_s
 | 
					    @formula_file_regex ||= case formula_dir
 | 
				
			||||||
    when "Formula"
 | 
					    when path/"Formula"
 | 
				
			||||||
      %r{^Formula(/[^/]+)+\.rb$}
 | 
					      %r{^Formula(/[^/]+)+\.rb$}
 | 
				
			||||||
    when "HomebrewFormula"
 | 
					    when path/"HomebrewFormula"
 | 
				
			||||||
      %r{^HomebrewFormula(/[^/]+)+\.rb$}
 | 
					      %r{^HomebrewFormula(/[^/]+)+\.rb$}
 | 
				
			||||||
    else
 | 
					    when path
 | 
				
			||||||
      %r{^[^/]+\.rb$}
 | 
					      %r{^[^/]+\.rb$}
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      raise ArgumentError, "Unexpected formula_dir: #{formula_dir}"
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  private :formula_file_regex
 | 
					  private :formula_file_regex
 | 
				
			||||||
 | 
				
			|||||||
@ -3,6 +3,7 @@
 | 
				
			|||||||
RSpec.describe Tap do
 | 
					RSpec.describe Tap do
 | 
				
			||||||
  include FileUtils
 | 
					  include FileUtils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  alias_matcher :have_cask_file, :be_cask_file
 | 
				
			||||||
  alias_matcher :have_formula_file, :be_formula_file
 | 
					  alias_matcher :have_formula_file, :be_formula_file
 | 
				
			||||||
  alias_matcher :have_custom_remote, :be_custom_remote
 | 
					  alias_matcher :have_custom_remote, :be_custom_remote
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -631,6 +632,103 @@ RSpec.describe Tap do
 | 
				
			|||||||
        expect(homebrew_foo_tap.pypi_formula_mappings).to eq expected_result
 | 
					        expect(homebrew_foo_tap.pypi_formula_mappings).to eq expected_result
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    describe "#formula_file?" do
 | 
				
			||||||
 | 
					      it "matches files from Formula/" do
 | 
				
			||||||
 | 
					        tap = described_class.fetch("hard/core")
 | 
				
			||||||
 | 
					        FileUtils.mkdir_p(tap.path/"Formula")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        %w[
 | 
				
			||||||
 | 
					          kvazaar.rb
 | 
				
			||||||
 | 
					          Casks/kvazaar.rb
 | 
				
			||||||
 | 
					          Casks/k/kvazaar.rb
 | 
				
			||||||
 | 
					          Formula/kvazaar.sh
 | 
				
			||||||
 | 
					          HomebrewFormula/kvazaar.rb
 | 
				
			||||||
 | 
					          HomebrewFormula/k/kvazaar.rb
 | 
				
			||||||
 | 
					        ].each do |relative_path|
 | 
				
			||||||
 | 
					          expect(tap).not_to have_formula_file(relative_path)
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        %w[
 | 
				
			||||||
 | 
					          Formula/kvazaar.rb
 | 
				
			||||||
 | 
					          Formula/k/kvazaar.rb
 | 
				
			||||||
 | 
					        ].each do |relative_path|
 | 
				
			||||||
 | 
					          expect(tap).to have_formula_file(relative_path)
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      ensure
 | 
				
			||||||
 | 
					        FileUtils.rm_rf(tap.path.parent) if tap
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it "matches files from HomebrewFormula/" do
 | 
				
			||||||
 | 
					        tap = described_class.fetch("hard/core")
 | 
				
			||||||
 | 
					        FileUtils.mkdir_p(tap.path/"HomebrewFormula")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        %w[
 | 
				
			||||||
 | 
					          kvazaar.rb
 | 
				
			||||||
 | 
					          Casks/kvazaar.rb
 | 
				
			||||||
 | 
					          Casks/k/kvazaar.rb
 | 
				
			||||||
 | 
					          Formula/kvazaar.rb
 | 
				
			||||||
 | 
					          Formula/k/kvazaar.rb
 | 
				
			||||||
 | 
					          HomebrewFormula/kvazaar.sh
 | 
				
			||||||
 | 
					        ].each do |relative_path|
 | 
				
			||||||
 | 
					          expect(tap).not_to have_formula_file(relative_path)
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        %w[
 | 
				
			||||||
 | 
					          HomebrewFormula/kvazaar.rb
 | 
				
			||||||
 | 
					          HomebrewFormula/k/kvazaar.rb
 | 
				
			||||||
 | 
					        ].each do |relative_path|
 | 
				
			||||||
 | 
					          expect(tap).to have_formula_file(relative_path)
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      ensure
 | 
				
			||||||
 | 
					        FileUtils.rm_rf(tap.path.parent) if tap
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it "matches files from the top-level directory" do
 | 
				
			||||||
 | 
					        tap = described_class.fetch("hard/core")
 | 
				
			||||||
 | 
					        FileUtils.mkdir_p(tap.path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        %w[
 | 
				
			||||||
 | 
					          kvazaar.sh
 | 
				
			||||||
 | 
					          Casks/kvazaar.rb
 | 
				
			||||||
 | 
					          Casks/k/kvazaar.rb
 | 
				
			||||||
 | 
					          Formula/kvazaar.rb
 | 
				
			||||||
 | 
					          Formula/k/kvazaar.rb
 | 
				
			||||||
 | 
					          HomebrewFormula/kvazaar.rb
 | 
				
			||||||
 | 
					          HomebrewFormula/k/kvazaar.rb
 | 
				
			||||||
 | 
					        ].each do |relative_path|
 | 
				
			||||||
 | 
					          expect(tap).not_to have_formula_file(relative_path)
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        expect(tap).to have_formula_file("kvazaar.rb")
 | 
				
			||||||
 | 
					      ensure
 | 
				
			||||||
 | 
					        FileUtils.rm_rf(tap.path.parent) if tap
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    describe "#cask_file?" do
 | 
				
			||||||
 | 
					      it "matches files from Casks/" do
 | 
				
			||||||
 | 
					        tap = described_class.fetch("hard/core")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        %w[
 | 
				
			||||||
 | 
					          kvazaar.rb
 | 
				
			||||||
 | 
					          Casks/kvazaar.sh
 | 
				
			||||||
 | 
					          Formula/kvazaar.rb
 | 
				
			||||||
 | 
					          Formula/k/kvazaar.rb
 | 
				
			||||||
 | 
					          HomebrewFormula/kvazaar.rb
 | 
				
			||||||
 | 
					          HomebrewFormula/k/kvazaar.rb
 | 
				
			||||||
 | 
					        ].each do |relative_path|
 | 
				
			||||||
 | 
					          expect(tap).not_to have_cask_file(relative_path)
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        %w[
 | 
				
			||||||
 | 
					          Casks/kvazaar.rb
 | 
				
			||||||
 | 
					          Casks/k/kvazaar.rb
 | 
				
			||||||
 | 
					        ].each do |relative_path|
 | 
				
			||||||
 | 
					          expect(tap).to have_cask_file(relative_path)
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe CoreTap do
 | 
					  describe CoreTap do
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user