summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2023-02-13 17:22:54 -0800
committergit <svn-admin@ruby-lang.org>2023-02-22 08:42:17 +0000
commit47d4f73ee755a0ae7b26eb2e35b820202e008763 (patch)
tree3b7b6f762ed7379cc84b2c3347dfb81a1ed07faa /test
parent612ebd10c061fefd6e4f1f736a95188bd6ae5146 (diff)
[rubygems/rubygems] Remove platform option for gem exec
Also fix native extensions that load dependencies https://github.com/rubygems/rubygems/commit/a06f9870c7
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/test_gem_commands_exec_command.rb148
1 files changed, 144 insertions, 4 deletions
diff --git a/test/rubygems/test_gem_commands_exec_command.rb b/test/rubygems/test_gem_commands_exec_command.rb
index f9a37b40fb..5f988d5b5c 100644
--- a/test/rubygems/test_gem_commands_exec_command.rb
+++ b/test/rubygems/test_gem_commands_exec_command.rb
@@ -15,6 +15,7 @@ class TestGemCommandsExecCommand < Gem::TestCase
@gem_home = Gem.dir
@gem_path = Gem.path
+ @test_arch = RbConfig::CONFIG["arch"]
@installed_specs = []
Gem.post_install {|installer| @installed_specs << installer.spec }
@@ -138,6 +139,147 @@ class TestGemCommandsExecCommand < Gem::TestCase
end
end
+ def test_gem_with_platforms
+ spec_fetcher do |fetcher|
+ fetcher.download "a", 2 do |s|
+ s.executables = %w[a]
+ s.files = %w[bin/a lib/a.rb]
+
+ write_file File.join(*%W[gems #{s.original_name} bin a]) do |f|
+ f << "Gem.ui.say #{s.original_name.dump}"
+ end
+ end
+
+ fetcher.download "a", 2 do |s|
+ s.executables = %w[a]
+ s.files = %w[bin/a lib/a.rb]
+ s.platform = "x86_64-darwin"
+
+ write_file File.join(*%W[gems #{s.original_name} bin a]) do |f|
+ f << "Gem.ui.say #{s.original_name.dump}"
+ end
+ end
+ end
+
+ use_ui @ui do
+ invoke "a:2"
+ assert_equal "a-2\n", @ui.output
+ end
+
+ use_ui @ui do
+ util_set_arch "x86_64-darwin-18"
+ invoke "a:2"
+ assert_equal "a-2-x86_64-darwin\n", @ui.output
+ end
+ end
+
+ def test_gem_with_platform_dependencies
+ platforms = Gem.platforms.dup
+
+ spec_fetcher do |fetcher|
+ fetcher.download "a", 2 do |s|
+ s.executables = %w[a]
+ s.files = %w[bin/a lib/a.rb]
+ s.add_runtime_dependency "with_platform"
+
+ write_file File.join(*%W[gems #{s.original_name} bin a]) do |f|
+ f << 'require "with_platform"' << "\n"
+ f << 'Gem.ui.say Gem.loaded_specs.each_value.map(&:original_name).sort.join("\n")'
+ end
+ end
+
+ fetcher.download "with_platform", 2 do |s|
+ s.files = %w[lib/with_platform.rb]
+ s.platform = Gem::Platform.local
+ end
+
+ fetcher.download "with_platform", 2 do |s|
+ s.files = %w[lib/with_platform.rb]
+ end
+ end
+
+ use_ui @ui do
+ util_set_arch "unknown-unknown"
+ invoke "a"
+ assert_equal "a-2\nwith_platform-2\n", @ui.output
+ end
+
+ use_ui @ui do
+ util_set_arch @test_arch
+ invoke "a"
+ assert_empty @ui.error
+ assert_equal "a-2\nwith_platform-2-#{Gem::Platform.local}\n", @ui.output
+ end
+ end
+
+ def test_gem_with_platform_and_platform_dependencies
+ platforms = Gem.platforms.dup
+
+ spec_fetcher do |fetcher|
+ fetcher.download "a", 2 do |s|
+ s.executables = %w[a]
+ s.files = %w[bin/a lib/a.rb]
+ s.add_runtime_dependency "with_platform"
+ s.platform = Gem::Platform.local.to_s
+
+ write_file File.join(*%W[gems #{s.original_name} bin a]) do |f|
+ f << 'require "with_platform"' << "\n"
+ f << 'Gem.ui.say Gem.loaded_specs.each_value.map(&:original_name).sort.join("\n")'
+ end
+ end
+
+ fetcher.download "a", 2 do |s|
+ s.executables = %w[a]
+ s.files = %w[bin/a lib/a.rb extconf.rb]
+ s.add_runtime_dependency "with_platform"
+
+ write_file File.join(*%W[gems #{s.original_name} bin a]) do |f|
+ f << 'require "with_platform"' << "\n"
+ f << 'Gem.ui.say Gem.loaded_specs.each_value.map(&:original_name).sort.join("\n")'
+ end
+
+ s.extensions = %w[extconf.rb]
+ write_file File.join(*%W[gems #{s.original_name} extconf.rb]) do |f|
+ f.write <<-RUBY
+ gem('with_platform', '~> 2.0')
+ require 'with_platform'
+ gem 'sometimes_used'
+ require 'sometimes_used'
+ require "mkmf"
+ create_makefile("#{s.name}")
+ RUBY
+ end
+ end
+
+ fetcher.download "with_platform", 2 do |s|
+ s.files = %w[lib/with_platform.rb]
+ s.platform = Gem::Platform.local.to_s
+ end
+
+ fetcher.download "with_platform", 2 do |s|
+ s.files = %w[lib/with_platform.rb]
+ s.add_runtime_dependency "sometimes_used"
+ end
+
+ fetcher.download "sometimes_used", 2 do |s|
+ s.files = %w[lib/sometimes_used.rb]
+ end
+ end
+
+ use_ui @ui do
+ util_set_arch "unknown-unknown"
+ invoke "a"
+ assert_equal "Building native extensions. This could take a while...\na-2\nsometimes_used-2\nwith_platform-2\n", @ui.output
+ end
+
+ use_ui @ui do
+ util_set_arch @test_arch
+ invoke "a"
+ assert_empty @ui.error
+ assert_equal "a-2-#{Gem::Platform.local}\nwith_platform-2-#{Gem::Platform.local}\n", @ui.output
+ end
+ end
+
def test_gem_with_other_executable_name
spec_fetcher do |fetcher|
fetcher.gem "a", 2 do |s|
@@ -382,7 +524,7 @@ class TestGemCommandsExecCommand < Gem::TestCase
def test_pre_version_option
spec_fetcher do |fetcher|
- fetcher.gem "a", 1 do |s|
+ fetcher.download "a", 1 do |s|
s.executables = %w[foo]
s.files = %w[bin/foo lib/a.rb]
@@ -390,7 +532,7 @@ class TestGemCommandsExecCommand < Gem::TestCase
f << "Gem.ui.say #{s.original_name.dump} + ' ' + File.basename(__FILE__)"
end
end
- fetcher.gem "a", "1.1.a" do |s|
+ fetcher.download "a", "1.1.a" do |s|
s.executables = %w[foo ]
s.files = %w[bin/foo lib/a.rb]
@@ -400,8 +542,6 @@ class TestGemCommandsExecCommand < Gem::TestCase
end
end
- util_clear_gems
-
use_ui @ui do
@cmd.invoke "-v", ">= 0.a", "a"
assert_equal "a-1.1.a foo\n", @ui.output