| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "testing_env" | 
					
						
							|  |  |  | require "tmpdir" | 
					
						
							|  |  |  | require "extend/pathname" | 
					
						
							|  |  |  | require "install_renamed" | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-26 22:02:14 -04:00
										 |  |  | module PathnameTestExtension | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   include FileUtils | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def setup | 
					
						
							| 
									
										
										
										
											2015-04-28 22:37:27 -04:00
										 |  |  |     @src  = Pathname.new(mktmpdir) | 
					
						
							|  |  |  |     @dst  = Pathname.new(mktmpdir) | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @file = @src+"foo" | 
					
						
							|  |  |  |     @dir  = @src+"bar" | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def teardown | 
					
						
							|  |  |  |     rmtree(@src) | 
					
						
							|  |  |  |     rmtree(@dst) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-03-26 22:02:14 -04:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PathnameTests < Homebrew::TestCase | 
					
						
							|  |  |  |   include PathnameTestExtension | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_rmdir_if_possible | 
					
						
							|  |  |  |     mkdir_p @dir | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     touch @dir+"foo" | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     assert !@dir.rmdir_if_possible | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     assert_predicate @dir, :directory? | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     rm_f @dir+"foo" | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |     assert @dir.rmdir_if_possible | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     refute_predicate @dir, :exist? | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_rmdir_if_possible_ignore_DS_Store | 
					
						
							|  |  |  |     mkdir_p @dir | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     touch @dir+".DS_Store" | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |     assert @dir.rmdir_if_possible | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     refute_predicate @dir, :exist? | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_write | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @file.write("CONTENT") | 
					
						
							|  |  |  |     assert_equal "CONTENT", File.read(@file) | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_write_does_not_overwrite | 
					
						
							|  |  |  |     touch @file | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_raises(RuntimeError) { @file.write("CONTENT") } | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_atomic_write | 
					
						
							|  |  |  |     touch @file | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @file.atomic_write("CONTENT") | 
					
						
							|  |  |  |     assert_equal "CONTENT", File.read(@file) | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-22 10:20:39 -05:00
										 |  |  |   def test_atomic_write_preserves_permissions | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     File.open(@file, "w", 0100777) {} | 
					
						
							| 
									
										
										
										
											2014-03-22 10:20:39 -05:00
										 |  |  |     @file.atomic_write("CONTENT") | 
					
						
							|  |  |  |     assert_equal 0100777 & ~File.umask, @file.stat.mode | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_atomic_write_preserves_default_permissions | 
					
						
							|  |  |  |     @file.atomic_write("CONTENT") | 
					
						
							|  |  |  |     sentinel = @file.parent.join("sentinel") | 
					
						
							|  |  |  |     touch sentinel | 
					
						
							|  |  |  |     assert_equal sentinel.stat.mode, @file.stat.mode | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   def test_ensure_writable | 
					
						
							|  |  |  |     touch @file | 
					
						
							|  |  |  |     chmod 0555, @file | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     @file.ensure_writable { assert_predicate @file, :writable? } | 
					
						
							|  |  |  |     refute_predicate @file, :writable? | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_extname | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_equal ".tar.gz", Pathname("foo-0.1.tar.gz").extname | 
					
						
							|  |  |  |     assert_equal ".cpio.gz", Pathname("foo-0.1.cpio.gz").extname | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_stem | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_equal "foo-0.1", Pathname("foo-0.1.tar.gz").stem | 
					
						
							|  |  |  |     assert_equal "foo-0.1", Pathname("foo-0.1.cpio.gz").stem | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_install_missing_file | 
					
						
							| 
									
										
										
										
											2014-07-10 21:26:54 -05:00
										 |  |  |     assert_raises(Errno::ENOENT) { @dst.install "non_existent_file" } | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_install_removes_original | 
					
						
							|  |  |  |     touch @file | 
					
						
							| 
									
										
										
										
											2013-08-12 20:55:24 -07:00
										 |  |  |     @dst.install(@file) | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     assert_predicate @dst/@file.basename, :exist? | 
					
						
							|  |  |  |     refute_predicate @file, :exist? | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  |   def test_install_creates_intermediate_directories | 
					
						
							|  |  |  |     touch @file | 
					
						
							|  |  |  |     refute_predicate @dir, :directory? | 
					
						
							|  |  |  |     @dir.install(@file) | 
					
						
							|  |  |  |     assert_predicate @dir, :directory? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_install_renamed | 
					
						
							| 
									
										
										
										
											2015-03-26 22:02:14 -04:00
										 |  |  |     @dst.extend(InstallRenamed) | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @file.write "a" | 
					
						
							| 
									
										
										
										
											2015-03-26 22:02:14 -04:00
										 |  |  |     @dst.install @file | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  |     @file.write "b" | 
					
						
							| 
									
										
										
										
											2015-03-26 22:02:14 -04:00
										 |  |  |     @dst.install @file | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-26 22:02:14 -04:00
										 |  |  |     assert_equal "a", File.read(@dst+@file.basename) | 
					
						
							|  |  |  |     assert_equal "b", File.read(@dst+"#{@file.basename}.default") | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-03-26 22:02:15 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_install_renamed_directory | 
					
						
							|  |  |  |     @dst.extend(InstallRenamed) | 
					
						
							|  |  |  |     @file.write "a" | 
					
						
							|  |  |  |     @dst.install @src | 
					
						
							|  |  |  |     assert_equal "a", File.read(@dst+@src.basename+@file.basename) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-03-26 22:02:15 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_cp_path_sub_file | 
					
						
							|  |  |  |     @file.write "a" | 
					
						
							|  |  |  |     @file.cp_path_sub @src, @dst | 
					
						
							|  |  |  |     assert_equal "a", File.read(@dst+"foo") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_cp_path_sub_directory | 
					
						
							|  |  |  |     @dir.mkpath | 
					
						
							|  |  |  |     @dir.cp_path_sub @src, @dst | 
					
						
							|  |  |  |     assert_predicate @dst+@dir.basename, :directory? | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-26 22:02:14 -04:00
										 |  |  | class PathnameInstallTests < Homebrew::TestCase | 
					
						
							|  |  |  |   include PathnameTestExtension | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  |   def setup | 
					
						
							|  |  |  |     super | 
					
						
							|  |  |  |     (@src+"a.txt").write "This is sample file a." | 
					
						
							|  |  |  |     (@src+"b.txt").write "This is sample file b." | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_install | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  |     @dst.install @src+"a.txt" | 
					
						
							| 
									
										
										
										
											2015-03-25 21:11:51 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     assert_predicate @dst+"a.txt", :exist?, "a.txt was not installed" | 
					
						
							|  |  |  |     refute_predicate @dst+"b.txt", :exist?, "b.txt was installed." | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_install_list | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  |     @dst.install [@src+"a.txt", @src+"b.txt"] | 
					
						
							| 
									
										
										
										
											2015-03-25 21:11:51 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     assert_predicate @dst+"a.txt", :exist?, "a.txt was not installed" | 
					
						
							|  |  |  |     assert_predicate @dst+"b.txt", :exist?, "b.txt was not installed" | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_install_glob | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  |     @dst.install Dir[@src+"*.txt"] | 
					
						
							| 
									
										
										
										
											2015-03-25 21:11:51 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     assert_predicate @dst+"a.txt", :exist?, "a.txt was not installed" | 
					
						
							|  |  |  |     assert_predicate @dst+"b.txt", :exist?, "b.txt was not installed" | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_install_directory | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  |     bin = @src+"bin" | 
					
						
							|  |  |  |     bin.mkpath | 
					
						
							|  |  |  |     mv Dir[@src+"*.txt"], bin | 
					
						
							|  |  |  |     @dst.install bin | 
					
						
							| 
									
										
										
										
											2015-03-25 21:11:51 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     assert_predicate @dst+"bin/a.txt", :exist?, "a.txt was not installed" | 
					
						
							|  |  |  |     assert_predicate @dst+"bin/b.txt", :exist?, "b.txt was not installed" | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_install_rename | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  |     @dst.install @src+"a.txt" => "c.txt" | 
					
						
							| 
									
										
										
										
											2015-03-25 21:11:51 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     assert_predicate @dst+"c.txt", :exist?, "c.txt was not installed" | 
					
						
							|  |  |  |     refute_predicate @dst+"a.txt", :exist?, "a.txt was installed but not renamed" | 
					
						
							|  |  |  |     refute_predicate @dst+"b.txt", :exist?, "b.txt was installed" | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_install_rename_more | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  |     @dst.install(@src+"a.txt" => "c.txt", @src+"b.txt" => "d.txt") | 
					
						
							| 
									
										
										
										
											2015-03-25 21:11:51 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     assert_predicate @dst+"c.txt", :exist?, "c.txt was not installed" | 
					
						
							|  |  |  |     assert_predicate @dst+"d.txt", :exist?, "d.txt was not installed" | 
					
						
							|  |  |  |     refute_predicate @dst+"a.txt", :exist?, "a.txt was installed but not renamed" | 
					
						
							|  |  |  |     refute_predicate @dst+"b.txt", :exist?, "b.txt was installed but not renamed" | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_install_rename_directory | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  |     bin = @src+"bin" | 
					
						
							|  |  |  |     bin.mkpath | 
					
						
							|  |  |  |     mv Dir[@src+"*.txt"], bin | 
					
						
							|  |  |  |     @dst.install bin => "libexec" | 
					
						
							| 
									
										
										
										
											2015-03-25 21:11:51 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     refute_predicate @dst+"bin", :exist?, "bin was installed but not renamed" | 
					
						
							|  |  |  |     assert_predicate @dst+"libexec/a.txt", :exist?, "a.txt was not installed" | 
					
						
							|  |  |  |     assert_predicate @dst+"libexec/b.txt", :exist?, "b.txt was not installed" | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_install_symlink | 
					
						
							| 
									
										
										
										
											2015-03-25 21:37:26 -04:00
										 |  |  |     bin = @src+"bin" | 
					
						
							|  |  |  |     bin.mkpath | 
					
						
							|  |  |  |     mv Dir[@src+"*.txt"], bin | 
					
						
							|  |  |  |     @dst.install_symlink bin | 
					
						
							| 
									
										
										
										
											2014-03-18 19:03:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-25 21:11:51 -04:00
										 |  |  |     assert_predicate @dst+"bin", :symlink? | 
					
						
							|  |  |  |     assert_predicate @dst+"bin", :directory? | 
					
						
							|  |  |  |     assert_predicate @dst+"bin/a.txt", :exist? | 
					
						
							|  |  |  |     assert_predicate @dst+"bin/b.txt", :exist? | 
					
						
							|  |  |  |     assert_predicate (@dst+"bin").readlink, :relative? | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-05-21 20:43:38 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_install_relative_symlink | 
					
						
							|  |  |  |     @dst.install_symlink "foo" => "bar" | 
					
						
							|  |  |  |     assert_equal Pathname.new("foo"), (@dst+"bar").readlink | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-04-10 15:02:45 -05:00
										 |  |  | end |