Permalink
Browse files

Check writability of bindir, create bindir in the right tests, use "s…

…ay" properly.

Also wrap chmodding tests in "if not win_platform?"


git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1812 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information...
1 parent dd7cefd commit 8f0c9c8bb802aa9236bc3469792006139baca43d technomancy committed Jun 24, 2008
Showing with 43 additions and 20 deletions.
  1. +5 −4 lib/rubygems/installer.rb
  2. +38 −16 test/test_gem_installer.rb
@@ -85,11 +85,12 @@ def initialize(gem, options={})
raise Gem::InstallError, "invalid gem format for #{@gem}"
end
- if !File.writable? @gem_home # TODO: or !File.writable? RbConfig::CONFIG['bindir']
+ if !File.writable? @gem_home or
+ (File.exist? Gem.bindir and !File.writable? Gem.bindir)
if options[:user_install] == false # You explicitly don't want to use ~
raise Gem::FilePermissionError, @gem_home
elsif options[:user_install].nil?
- $stderr.puts "Warning: falling back to user-level install since #{@gem_home} and #{@bin_dir} aren't both writable."
+ say "Warning: falling back to user-level install since #{@gem_home} and #{@bin_dir} aren't both writable."
end
options[:user_install] = true
end
@@ -99,8 +100,8 @@ def initialize(gem, options={})
user_bin_dir = File.join(@gem_home, 'gems', 'bin')
if !ENV['PATH'].split(':').include?(user_bin_dir)
- $stderr.puts "You don't have #{user_bin_dir} in your PATH."
- $stderr.puts "You won't be able to run gem-installed executables until you add it."
+ say "You don't have #{user_bin_dir} in your PATH."
+ say "You won't be able to run gem-installed executables until you add it."
end
Dir.mkdir @gem_home if ! File.directory? @gem_home
View
@@ -515,6 +515,7 @@ def test_initialize
spec = quick_gem 'a' do |s| s.platform = Gem::Platform.new 'mswin32' end
gem = File.join @tempdir, "#{spec.full_name}.gem"
+ Dir.mkdir util_inst_bindir
util_build_gem spec
FileUtils.mv File.join(@gemhome, 'cache', "#{spec.full_name}.gem"),
@tempdir
@@ -525,6 +526,7 @@ def test_initialize
end
def test_install
+ Dir.mkdir util_inst_bindir
util_setup_gem
use_ui @ui do
@@ -593,6 +595,7 @@ def test_install_force
end
def test_install_ignore_dependencies
+ Dir.mkdir util_inst_bindir
@spec.add_dependency 'b', '> 5'
util_setup_gem
@installer.ignore_dependencies = true
@@ -634,24 +637,43 @@ def test_install_missing_dirs
assert File.exist?(File.join(@gemhome, 'specifications',
"#{@spec.full_name}.gemspec"))
end
+ unless win_platform? # File.chmod doesn't work
+ def test_install_user_local_fallback
+ Dir.mkdir util_inst_bindir
+ File.chmod 0755, @userhome
+ File.chmod 0000, util_inst_bindir
+ File.chmod 0000, Gem.dir
+ install_dir = File.join @userhome, '.gem', 'gems', @spec.full_name
+ @spec.executables = ["executable"]
- def test_install_user_local_fallback
- Dir.mkdir util_inst_bindir
- File.chmod 0755, @userhome
- File.chmod 0000, util_inst_bindir
- File.chmod 0000, Gem.dir
- install_dir = File.join @userhome, '.gem', 'gems', @spec.full_name
- @spec.executables = ["executable"]
-
- util_setup_gem
- @installer.install
+ use_ui @ui do
+ util_setup_gem
+ @installer.install
+ end
- assert File.exist?(File.join(install_dir, 'lib', 'code.rb'))
- assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable'))
- ensure
- File.chmod 0755, Gem.dir
- File.chmod 0755, util_inst_bindir
- end unless win_platform? # File.chmod doesn't work
+ assert File.exist?(File.join(install_dir, 'lib', 'code.rb'))
+ assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable'))
+ ensure
+ File.chmod 0755, Gem.dir
+ File.chmod 0755, util_inst_bindir
+ end
+
+ def test_install_bindir_read_only
+ Dir.mkdir util_inst_bindir
+ File.chmod 0755, @userhome
+ File.chmod 0000, util_inst_bindir
+
+ use_ui @ui do
+ setup
+ util_setup_gem
+ @installer.install
+ end
+
+ assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable'))
+ ensure
+ File.chmod 0755, util_inst_bindir
+ end
+ end
def test_install_with_message
@spec.post_install_message = 'I am a shiny gem!'

0 comments on commit 8f0c9c8

Please sign in to comment.