Tests for Pathname+Yeast
I removed the rename and mv functions as when I wrote the tests I realised the function implied the pathname object would be updated to reflect the moved or renamed file. However that cannot be done. Also frankly I think writing it out in full makes clearer code.
This commit is contained in:
parent
fbda4b45d6
commit
422ec29363
@ -55,7 +55,10 @@ class HttpDownloadStrategy <AbstractDownloadStrategy
|
||||
else
|
||||
# we are assuming it is not an archive, use original filename
|
||||
# this behaviour is due to ScriptFileFormula expectations
|
||||
@dl.mv File.basename(@url)
|
||||
# So I guess we should cp, but we mv, for this historic reason
|
||||
# HOWEVER if this breaks some expectation you had we *will* change the
|
||||
# behaviour, just open an issue at github
|
||||
FileUtils.mv @dl, File.basename(@url)
|
||||
end
|
||||
end
|
||||
private
|
||||
|
||||
@ -25,16 +25,6 @@ require 'pathname'
|
||||
|
||||
# we enhance pathname to make our code more readable
|
||||
class Pathname
|
||||
def mv dst
|
||||
FileUtils.mv to_s, dst
|
||||
end
|
||||
|
||||
def rename newname
|
||||
dst=dirname+newname
|
||||
dst.unlink if dst.exist? and file?
|
||||
mv dst
|
||||
end
|
||||
|
||||
def install src
|
||||
if src.is_a? Array
|
||||
src.collect {|src| install src }
|
||||
@ -50,13 +40,14 @@ class Pathname
|
||||
# this function when installing from the temporary build directory
|
||||
FileUtils.mv src, to_s
|
||||
end
|
||||
return self+src
|
||||
src=Pathname.new src
|
||||
return self+src.basename
|
||||
end
|
||||
end
|
||||
|
||||
# we assume this pathname object is a file obviously
|
||||
def write content
|
||||
raise "Will not overwrite #{f}" if exist? and not ARGV.force?
|
||||
raise "Will not overwrite #{to_s}" if exist? and not ARGV.force?
|
||||
dirname.mkpath
|
||||
File.open(self, 'w') {|f| f.write content }
|
||||
end
|
||||
@ -67,6 +58,7 @@ class Pathname
|
||||
else
|
||||
FileUtils.cp_r to_s, dst
|
||||
end
|
||||
return dst
|
||||
end
|
||||
|
||||
# extended to support the double extensions .tar.gz and .tar.bz2
|
||||
@ -86,8 +78,10 @@ class Pathname
|
||||
# instead rely on good ol' libc and the filesystem
|
||||
def rmdir_if_possible
|
||||
rmdir
|
||||
true
|
||||
rescue SystemCallError => e
|
||||
raise unless e.errno == Errno::ENOTEMPTY::Errno or e.errno == Errno::EACCES::Errno
|
||||
false
|
||||
end
|
||||
|
||||
def chmod_R perms
|
||||
@ -96,7 +90,10 @@ class Pathname
|
||||
end
|
||||
|
||||
def abv
|
||||
`find #{to_s} -type f | wc -l`.strip+' files, '+`du -hd0 #{to_s} | cut -d"\t" -f1`.strip
|
||||
out=''
|
||||
n=`find #{to_s} -type f | wc -l`.to_i
|
||||
out<<"#{n} files, " if n > 1
|
||||
out<<`du -hd0 #{to_s} | cut -d"\t" -f1`.strip
|
||||
end
|
||||
|
||||
def version
|
||||
|
||||
@ -362,4 +362,47 @@ class BeerTasting <Test::Unit::TestCase
|
||||
assert_equal 10.5, f-0.1
|
||||
assert_equal 10.7, f+0.1
|
||||
end
|
||||
|
||||
def test_pathname_plus_yeast
|
||||
nostdout do
|
||||
assert_nothing_raised do
|
||||
assert !Pathname.getwd.rmdir_if_possible
|
||||
assert !Pathname.getwd.abv.empty?
|
||||
|
||||
abcd=orig_abcd=HOMEBREW_CACHE+'abcd'
|
||||
FileUtils.cp ABS__FILE__, abcd
|
||||
abcd=HOMEBREW_PREFIX.install abcd
|
||||
assert (HOMEBREW_PREFIX+orig_abcd.basename).exist?
|
||||
assert abcd.exist?
|
||||
assert_equal HOMEBREW_PREFIX+'abcd', abcd
|
||||
|
||||
assert_raises(RuntimeError) {abcd.write 'CONTENT'}
|
||||
abcd.unlink
|
||||
abcd.write 'HELLOWORLD'
|
||||
assert_equal 'HELLOWORLD', File.read(abcd)
|
||||
|
||||
assert !orig_abcd.exist?
|
||||
rv=abcd.cp orig_abcd
|
||||
assert orig_abcd.exist?
|
||||
assert_equal rv, orig_abcd
|
||||
|
||||
orig_abcd.unlink
|
||||
assert !orig_abcd.exist?
|
||||
abcd.cp HOMEBREW_CACHE
|
||||
assert orig_abcd.exist?
|
||||
|
||||
foo1=HOMEBREW_CACHE+'foo-0.1.tar.gz'
|
||||
FileUtils.cp ABS__FILE__, foo1
|
||||
assert foo1.file?
|
||||
|
||||
assert_equal '.tar.gz', foo1.extname
|
||||
assert_equal 'foo-0.1', foo1.stem
|
||||
assert_equal '0.1', foo1.version
|
||||
|
||||
HOMEBREW_CACHE.chmod_R 0777
|
||||
end
|
||||
end
|
||||
|
||||
assert_raises(RuntimeError) {Pathname.getwd.install 'non_existant_file'}
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user