| 
									
										
										
										
											2016-07-16 21:08:10 +01:00
										 |  |  | require "testing_env" | 
					
						
							|  |  |  | require "keg" | 
					
						
							|  |  |  | require "stringio" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class OSMacLinkTests < Homebrew::TestCase | 
					
						
							|  |  |  |   include FileUtils | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def setup | 
					
						
							| 
									
										
										
										
											2017-01-21 11:21:30 +00:00
										 |  |  |     super | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 21:08:10 +01:00
										 |  |  |     keg = HOMEBREW_CELLAR.join("foo", "1.0") | 
					
						
							|  |  |  |     keg.join("bin").mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     %w[hiworld helloworld goodbye_cruel_world].each do |file| | 
					
						
							|  |  |  |       touch keg.join("bin", file) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @keg = Keg.new(keg) | 
					
						
							|  |  |  |     @dst = HOMEBREW_PREFIX.join("bin", "helloworld") | 
					
						
							|  |  |  |     @nonexistent = Pathname.new("/some/nonexistent/path") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @mode = OpenStruct.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @old_stdout = $stdout | 
					
						
							|  |  |  |     $stdout = StringIO.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mkpath HOMEBREW_PREFIX/"bin" | 
					
						
							|  |  |  |     mkpath HOMEBREW_PREFIX/"lib" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def teardown | 
					
						
							|  |  |  |     @keg.unlink | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $stdout = @old_stdout | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rmtree HOMEBREW_PREFIX/"lib" | 
					
						
							| 
									
										
										
										
											2017-01-21 11:21:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     super | 
					
						
							| 
									
										
										
										
											2016-07-16 21:08:10 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_mach_o_files_skips_hardlinks | 
					
						
							|  |  |  |     a = HOMEBREW_CELLAR/"a/1.0" | 
					
						
							|  |  |  |     (a/"lib").mkpath | 
					
						
							|  |  |  |     FileUtils.cp dylib_path("i386"), a/"lib/i386.dylib" | 
					
						
							|  |  |  |     FileUtils.ln a/"lib/i386.dylib", a/"lib/i386_link.dylib" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     keg = Keg.new(a) | 
					
						
							|  |  |  |     keg.link | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_equal 1, keg.mach_o_files.size | 
					
						
							|  |  |  |   ensure | 
					
						
							|  |  |  |     keg.unlink | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_mach_o_files_isnt_confused_by_symlinks | 
					
						
							|  |  |  |     a = HOMEBREW_CELLAR/"a/1.0" | 
					
						
							|  |  |  |     (a/"lib").mkpath | 
					
						
							|  |  |  |     FileUtils.cp dylib_path("i386"), a/"lib/i386.dylib" | 
					
						
							|  |  |  |     FileUtils.ln a/"lib/i386.dylib", a/"lib/i386_link.dylib" | 
					
						
							|  |  |  |     FileUtils.ln_s a/"lib/i386.dylib", a/"lib/1.dylib" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     keg = Keg.new(a) | 
					
						
							|  |  |  |     keg.link | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_equal 1, keg.mach_o_files.size | 
					
						
							|  |  |  |   ensure | 
					
						
							|  |  |  |     keg.unlink | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |