| 
									
										
										
										
											2022-02-26 17:23:41 -08:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "keg_relocate" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe Keg do | 
					
						
							| 
									
										
										
										
											2022-02-26 17:23:41 -08:00
										 |  |  |   subject(:keg) { described_class.new(HOMEBREW_CELLAR/"foo/1.0.0") } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let(:dir) { HOMEBREW_CELLAR/"foo/1.0.0" } | 
					
						
							|  |  |  |   let(:text_file) { dir/"file.txt" } | 
					
						
							|  |  |  |   let(:binary_file) { dir/"file.bin" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   before do | 
					
						
							|  |  |  |     dir.mkpath | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def setup_text_file | 
					
						
							|  |  |  |     text_file.atomic_write <<~EOS | 
					
						
							|  |  |  |       #{dir}/file.txt | 
					
						
							|  |  |  |       /foo#{dir}/file.txt | 
					
						
							|  |  |  |       foo/bar:#{dir}/file.txt | 
					
						
							|  |  |  |       foo/bar:/foo#{dir}/file.txt | 
					
						
							|  |  |  |       #{dir}/bar.txt:#{dir}/baz.txt | 
					
						
							|  |  |  |     EOS | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def setup_binary_file | 
					
						
							|  |  |  |     binary_file.atomic_write <<~EOS | 
					
						
							|  |  |  |       \x00 | 
					
						
							|  |  |  |     EOS | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#each_unique_file_matching" do | 
					
						
							|  |  |  |     specify "find string matches to path" do | 
					
						
							|  |  |  |       setup_text_file | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       string_matches = Set.new | 
					
						
							|  |  |  |       keg.each_unique_file_matching(dir) do |file| | 
					
						
							|  |  |  |         string_matches << file | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(string_matches.size).to eq 1
 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-05 19:24:55 -08:00
										 |  |  |   describe "#binary_file?" do | 
					
						
							|  |  |  |     specify "test if file has null bytes" do | 
					
						
							| 
									
										
										
										
											2022-02-26 17:23:41 -08:00
										 |  |  |       setup_binary_file | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-05 19:24:55 -08:00
										 |  |  |       expect(keg.binary_file?(binary_file)).to be true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       setup_text_file | 
					
						
							| 
									
										
										
										
											2022-02-26 17:23:41 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-05 19:24:55 -08:00
										 |  |  |       expect(keg.binary_file?(text_file)).to be false | 
					
						
							| 
									
										
										
										
											2022-02-26 17:23:41 -08:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |