diff options
Diffstat (limited to 'test/rubygems/test_gem_installer.rb')
-rw-r--r-- | test/rubygems/test_gem_installer.rb | 247 |
1 files changed, 141 insertions, 106 deletions
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 01b151c089..e513fe6da3 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -4,7 +4,6 @@ class TestGemInstaller < Gem::InstallerTestCase def setup super - common_installer_setup if __name__ =~ /^test_install(_|$)/ then FileUtils.rm_r @spec.gem_dir @@ -15,8 +14,6 @@ class TestGemInstaller < Gem::InstallerTestCase end def teardown - common_installer_teardown - super Gem.configuration = @config @@ -55,6 +52,95 @@ load Gem.bin_path('a', 'executable', version) assert_equal expected, wrapper end + def test_build_extensions_none + use_ui @ui do + @installer.build_extensions + end + + assert_equal '', @ui.output + assert_equal '', @ui.error + + refute File.exist?('gem_make.out') + end + + def test_build_extensions_extconf_bad + @installer.spec = @spec + @spec.extensions << 'extconf.rb' + + e = assert_raises Gem::Installer::ExtensionBuildError do + use_ui @ui do + @installer.build_extensions + end + end + + assert_match(/\AERROR: Failed to build gem native extension.$/, e.message) + + assert_equal "Building native extensions. This could take a while...\n", + @ui.output + assert_equal '', @ui.error + + gem_make_out = File.join @gemhome, 'gems', @spec.full_name, 'gem_make.out' + + assert_match %r%#{Regexp.escape Gem.ruby} extconf\.rb%, + File.read(gem_make_out) + assert_match %r%#{Regexp.escape Gem.ruby}: No such file%, + File.read(gem_make_out) + end + + def test_build_extensions_unsupported + @installer.spec = @spec + FileUtils.mkdir_p @spec.gem_dir + gem_make_out = File.join @spec.gem_dir, 'gem_make.out' + @spec.extensions << nil + + e = assert_raises Gem::Installer::ExtensionBuildError do + use_ui @ui do + @installer.build_extensions + end + end + + assert_match(/^\s*No builder for extension ''$/, e.message) + + assert_equal "Building native extensions. This could take a while...\n", + @ui.output + assert_equal '', @ui.error + + assert_equal "No builder for extension ''\n", File.read(gem_make_out) + ensure + FileUtils.rm_f gem_make_out + end + + def test_build_extensions_with_build_args + args = ["--aa", "--bb"] + @installer.build_args = args + @installer.spec = @spec + @spec.extensions << 'extconf.rb' + + File.open File.join(@spec.gem_dir, "extconf.rb"), "w" do |f| + f.write <<-'RUBY' + puts "IN EXTCONF" + extconf_args = File.join File.dirname(__FILE__), 'extconf_args' + File.open extconf_args, 'w' do |f| + f.puts ARGV.inspect + end + + File.open 'Makefile', 'w' do |f| + f.puts "default:\n\techo built" + f.puts "install:\n\techo installed" + end + RUBY + end + + use_ui @ui do + @installer.build_extensions + end + + path = File.join @spec.gem_dir, "extconf_args" + + assert_equal args.inspect, File.read(path).strip + assert File.directory? File.join(@spec.gem_dir, 'lib') + end + def test_check_executable_overwrite @installer.generate_bin @@ -73,7 +159,7 @@ load Gem.bin_path('a', 'executable', version) @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec + assert File.exist? installed_exec wrapper = File.read installed_exec assert_match %r|generated by RubyGems|, wrapper @@ -136,7 +222,7 @@ gem 'other', version @installer.generate_bin # should not raise installed_exec = File.join util_inst_bindir, 'foo-executable-bar' - assert_path_exists installed_exec + assert File.exist? installed_exec wrapper = File.read installed_exec assert_match %r|generated by RubyGems|, wrapper @@ -165,7 +251,7 @@ gem 'other', version @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec + assert File.exist? installed_exec wrapper = File.read installed_exec assert_match %r|generated by RubyGems|, wrapper @@ -178,7 +264,7 @@ gem 'other', version @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec + assert File.exist? installed_exec wrapper = File.read installed_exec assert_match %r|generated by RubyGems|, wrapper @@ -214,8 +300,6 @@ gem 'other', version end def test_ensure_loadable_spec_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - _, a_gem = util_gem 'a', 2 do |s| s.add_dependency 'garbage ~> 5' end @@ -252,7 +336,7 @@ gem 'other', version assert_equal true, File.directory?(util_inst_bindir) installed_exec = File.join(util_inst_bindir, 'executable') - assert_path_exists installed_exec + assert_equal true, File.exist?(installed_exec) assert_equal mask, File.stat(installed_exec).mode unless win_platform? wrapper = File.read installed_exec @@ -287,7 +371,7 @@ gem 'other', version @installer.generate_bin assert File.directory? util_inst_bindir installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec + assert File.exist? installed_exec assert_equal mask, File.stat(installed_exec).mode unless win_platform? wrapper = File.read installed_exec @@ -304,7 +388,7 @@ gem 'other', version @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) installed_exec = File.join util_inst_bindir, 'foo-executable-bar' - assert_path_exists installed_exec + assert_equal true, File.exist?(installed_exec) ensure Gem::Installer.exec_format = nil end @@ -318,7 +402,7 @@ gem 'other', version @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec + assert_equal true, File.exist?(installed_exec) ensure Gem::Installer.exec_format = nil end @@ -340,7 +424,7 @@ gem 'other', version @installer.generate_bin installed_exec = File.join("#{@gemhome}2", "bin", 'executable') - assert_path_exists installed_exec + assert File.exist? installed_exec assert_equal mask, File.stat(installed_exec).mode unless win_platform? wrapper = File.read installed_exec @@ -353,7 +437,7 @@ gem 'other', version @installer.wrappers = true @installer.generate_bin - refute_path_exists util_inst_bindir, 'bin dir was created when not needed' + refute File.exist?(util_inst_bindir), 'bin dir was created when not needed' end def test_generate_bin_script_no_perms @@ -389,7 +473,7 @@ gem 'other', version @installer.generate_bin installed_exec = File.join @gemhome, 'bin', 'executable' - assert_path_exists installed_exec + assert_equal true, File.exist?(installed_exec) assert_equal mask, File.stat(installed_exec).mode unless win_platform? wrapper = File.read installed_exec @@ -414,7 +498,7 @@ gem 'other', version @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - assert_path_exists installed_exec + assert_equal true, File.exist?(installed_exec) assert_equal mask, File.stat(installed_exec).mode unless win_platform? assert_match %r|generated by RubyGems|, File.read(installed_exec) @@ -444,7 +528,7 @@ gem 'other', version @installer.wrappers = false @installer.generate_bin - refute_path_exists util_inst_bindir + refute File.exist?(util_inst_bindir) end def test_generate_bin_symlink_no_perms @@ -543,7 +627,7 @@ gem 'other', version @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec + assert File.exist? installed_exec @spec = Gem::Specification.new do |s| s.files = ['lib/code.rb'] @@ -580,7 +664,7 @@ gem 'other', version assert_equal true, File.directory?(util_inst_bindir) installed_exec = File.join(util_inst_bindir, 'executable') - assert_path_exists installed_exec + assert_equal true, File.exist?(installed_exec) assert_match(/Unable to use symlinks on Windows, installing wrapper/i, @ui.error) @@ -647,19 +731,19 @@ gem 'other', version rakefile = File.join gemdir, 'ext', 'a', 'Rakefile' Gem.pre_install do |installer| - refute_path_exists cache_file, 'cache file must not exist yet' + refute File.exist?(cache_file), 'cache file must not exist yet' true end Gem.post_build do |installer| - assert_path_exists gemdir, 'gem install dir must exist' - assert_path_exists rakefile, 'gem executable must exist' - refute_path_exists stub_exe, 'gem executable must not exist' + assert File.exist?(gemdir), 'gem install dir must exist' + assert File.exist?(rakefile), 'gem executable must exist' + refute File.exist?(stub_exe), 'gem executable must not exist' true end Gem.post_install do |installer| - assert_path_exists cache_file, 'cache file must exist' + assert File.exist?(cache_file), 'cache file must exist' end @newspec = nil @@ -670,23 +754,23 @@ gem 'other', version end assert_equal @spec, @newspec - assert_path_exists gemdir - assert_path_exists stub_exe, 'gem executable must exist' + assert File.exist? gemdir + assert File.exist?(stub_exe), 'gem executable must exist' exe = File.join gemdir, 'bin', 'executable' - assert_path_exists exe + assert File.exist? exe exe_mode = File.stat(exe).mode & 0111 assert_equal 0111, exe_mode, "0%o" % exe_mode unless win_platform? - assert_path_exists File.join gemdir, 'lib', 'code.rb' + assert File.exist?(File.join(gemdir, 'lib', 'code.rb')) - assert_path_exists rakefile + assert File.exist? rakefile spec_file = File.join(@gemhome, 'specifications', @spec.spec_name) assert_equal spec_file, @newspec.loaded_from - assert_path_exists spec_file + assert File.exist?(spec_file) assert_same @installer, @post_build_hook_arg assert_same @installer, @post_install_hook_arg @@ -795,7 +879,7 @@ gem 'other', version end gemdir = File.join(@gemhome, 'gems', @spec.full_name) - assert_path_exists File.join gemdir, 'lib', 'code.rb' + assert File.exist?(File.join(gemdir, 'lib', 'code.rb')) util_setup_gem # Morph spec to have lib/other.rb instead of code.rb and recreate @@ -814,9 +898,9 @@ gem 'other', version end end - assert_path_exists File.join gemdir, 'lib', 'other.rb' - refute_path_exists File.join gemdir, 'lib', 'code.rb', - "code.rb from prior install of same gem shouldn't remain here" + assert File.exist?(File.join(gemdir, 'lib', 'other.rb')) + refute(File.exist?(File.join(gemdir, 'lib', 'code.rb')), + "code.rb from prior install of same gem shouldn't remain here") end def test_install_force @@ -826,7 +910,7 @@ gem 'other', version end gem_dir = File.join(@gemhome, 'gems', 'old_ruby_required-1') - assert_path_exists gem_dir + assert File.exist?(gem_dir) end def test_install_missing_dirs @@ -842,8 +926,8 @@ gem 'other', version File.directory? File.join(Gem.dir, 'docs') File.directory? File.join(Gem.dir, 'specifications') - assert_path_exists File.join @gemhome, 'cache', @spec.file_name - assert_path_exists File.join @gemhome, 'specifications', @spec.spec_name + assert File.exist?(File.join(@gemhome, 'cache', @spec.file_name)) + assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name)) end def test_install_post_build_false @@ -864,10 +948,10 @@ gem 'other', version end spec_file = File.join @gemhome, 'specifications', @spec.spec_name - refute_path_exists spec_file + refute File.exist? spec_file gem_dir = File.join @gemhome, 'gems', @spec.full_name - refute_path_exists gem_dir + refute File.exist? gem_dir end def test_install_post_build_nil @@ -882,10 +966,10 @@ gem 'other', version end spec_file = File.join @gemhome, 'specifications', @spec.spec_name - assert_path_exists spec_file + assert File.exist? spec_file gem_dir = File.join @gemhome, 'gems', @spec.full_name - assert_path_exists gem_dir + assert File.exist? gem_dir end def test_install_pre_install_false @@ -906,7 +990,7 @@ gem 'other', version end spec_file = File.join @gemhome, 'specifications', @spec.spec_name - refute_path_exists spec_file + refute File.exist? spec_file end def test_install_pre_install_nil @@ -921,7 +1005,7 @@ gem 'other', version end spec_file = File.join @gemhome, 'specifications', @spec.spec_name - assert_path_exists spec_file + assert File.exist? spec_file end def test_install_with_message @@ -937,31 +1021,6 @@ gem 'other', version assert_match %r|I am a shiny gem!|, @ui.output end - def test_install_extension_install_dir - gemhome2 = "#{@gemhome}2" - - @spec.extensions << "extconf.rb" - write_file File.join(@tempdir, "extconf.rb") do |io| - io.write <<-RUBY - require "mkmf" - create_makefile("#{@spec.name}") - RUBY - end - - @spec.files += %w[extconf.rb] - - use_ui @ui do - path = Gem::Package.build @spec - - installer = Gem::Installer.new path, :install_dir => gemhome2 - installer.install - end - - expected_makefile = File.join gemhome2, 'gems', @spec.full_name, 'Makefile' - - assert_path_exists expected_makefile - end - def test_install_extension_and_script @spec.extensions << "extconf.rb" write_file File.join(@tempdir, "extconf.rb") do |io| @@ -988,16 +1047,16 @@ gem 'other', version RUBY end - refute_path_exists File.join @spec.gem_dir, rb - refute_path_exists File.join @spec.gem_dir, rb2 + assert !File.exist?(File.join(@spec.gem_dir, rb)) + assert !File.exist?(File.join(@spec.gem_dir, rb2)) use_ui @ui do path = Gem::Package.build @spec @installer = Gem::Installer.new path @installer.install end - assert_path_exists File.join @spec.gem_dir, rb - assert_path_exists File.join @spec.gem_dir, rb2 + assert File.exist?(File.join(@spec.gem_dir, rb)) + assert File.exist?(File.join(@spec.gem_dir, rb2)) end def test_install_extension_flat @@ -1026,14 +1085,14 @@ gem 'other', version } so = File.join(@spec.gem_dir, "#{@spec.name}.#{RbConfig::CONFIG["DLEXT"]}") - refute_path_exists so + assert !File.exist?(so) use_ui @ui do path = Gem::Package.build @spec @installer = Gem::Installer.new path @installer.install end - assert_path_exists so + assert File.exist?(so) rescue puts '-' * 78 puts File.read File.join(@gemhome, 'gems', 'a-2', 'Makefile') @@ -1278,11 +1337,11 @@ gem 'other', version @installer.unpack dest - assert_path_exists File.join dest, 'lib', 'code.rb' - assert_path_exists File.join dest, 'bin', 'executable' + assert File.exist?(File.join(dest, 'lib', 'code.rb')) + assert File.exist?(File.join(dest, 'bin', 'executable')) end - def test_write_build_info_file + def test_write_build_args refute_path_exists @spec.build_info_file @installer.build_args = %w[ @@ -1298,7 +1357,7 @@ gem 'other', version assert_equal expected, File.read(@spec.build_info_file) end - def test_write_build_info_file_empty + def test_write_build_args_empty refute_path_exists @spec.build_info_file @installer.write_build_info_file @@ -1338,20 +1397,20 @@ gem 'other', version def test_write_spec FileUtils.rm @spec.spec_file - refute_path_exists @spec.spec_file + refute File.exist?(@spec.spec_file) @installer.spec = @spec @installer.gem_home = @gemhome @installer.write_spec - assert_path_exists @spec.spec_file + assert File.exist?(@spec.spec_file) assert_equal @spec, eval(File.read(@spec.spec_file)) end def test_write_spec_writes_cached_spec FileUtils.rm @spec.spec_file - refute_path_exists @spec.spec_file + refute File.exist?(@spec.spec_file) @spec.files = %w[a.rb b.rb c.rb] @@ -1370,30 +1429,6 @@ gem 'other', version assert_match %r!/gemhome/gems/a-2$!, @installer.dir end - def test_default_gem - FileUtils.rm_f File.join(Gem.dir, 'specifications') - - @installer.wrappers = true - @installer.options[:install_as_default] = true - @installer.gem_dir = util_gem_dir @spec - @installer.generate_bin - - use_ui @ui do - @installer.install - end - - assert File.directory? util_inst_bindir - installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec - - assert File.directory? File.join(Gem.dir, 'specifications') - assert File.directory? File.join(Gem.dir, 'specifications', 'default') - - default_spec = eval File.read File.join(Gem.dir, 'specifications', 'default', 'a-2.gemspec') - assert_equal Gem::Version.new("2"), default_spec.version - assert_equal ['bin/executable'], default_spec.files - end - def old_ruby_required spec = quick_spec 'old_ruby_required', '1' do |s| s.required_ruby_version = '= 1.4.6' |