Skip to content

Commit

Permalink
[rubygems/rubygems] Minor Bundler spec improvements
Browse files Browse the repository at this point in the history
While working on something else I noticed:

* Usage of uppercased "RUBY" and "JAVA" as platforms, when those don't
  really exist.
* Usage of some test gems with "1.0" as gemspec version and "1.0.0" as
  actual version.

This commit fixes both inconsistencies to make things more expectable.

rubygems/rubygems@e3ec32e247
  • Loading branch information
deivid-rodriguez authored and matzbot committed Jul 9, 2024
1 parent ac0e0f0 commit 1d97c46
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 86 deletions.
3 changes: 1 addition & 2 deletions spec/bundler/commands/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@
source "https://gem.repo1"
gem "platform_specific"
G
run "require 'platform_specific' ; puts PLATFORM_SPECIFIC"
expect(out).to eq("1.0.0 RUBY")
expect(the_bundle).to include_gems("platform_specific 1.0 ruby")
end

it "does not update the cache if --no-cache is passed" do
Expand Down
14 changes: 4 additions & 10 deletions spec/bundler/commands/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,12 @@

describe "with a gem that installs multiple platforms" do
it "installs gems for the local platform as first choice" do
skip "version is 1.0, not 1.0.0" if Gem.win_platform?

install_gemfile <<-G
source "https://gem.repo1"
gem "platform_specific"
G

run "require 'platform_specific' ; puts PLATFORM_SPECIFIC"
expect(out).to eq("1.0.0 #{Bundler.local_platform}")
expect(the_bundle).to include_gems("platform_specific 1.0 #{Bundler.local_platform}")
end

it "falls back on plain ruby" do
Expand All @@ -267,8 +264,7 @@
gem "platform_specific"
G

run "require 'platform_specific' ; puts PLATFORM_SPECIFIC"
expect(out).to eq("1.0.0 RUBY")
expect(the_bundle).to include_gems("platform_specific 1.0 ruby")
end

it "installs gems for java" do
Expand All @@ -278,8 +274,7 @@
gem "platform_specific"
G

run "require 'platform_specific' ; puts PLATFORM_SPECIFIC"
expect(out).to eq("1.0.0 JAVA")
expect(the_bundle).to include_gems("platform_specific 1.0 java")
end

it "installs gems for windows" do
Expand All @@ -290,8 +285,7 @@
gem "platform_specific"
G

run "require 'platform_specific' ; puts PLATFORM_SPECIFIC"
expect(out).to eq("1.0 x86-mswin32")
expect(the_bundle).to include_gems("platform_specific 1.0 x86-mswin32")
end
end

Expand Down
40 changes: 13 additions & 27 deletions spec/bundler/install/gemfile/force_ruby_platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@
before do
build_repo4 do
# Build a gem with platform specific versions
build_gem("platform_specific") do |s|
s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 RUBY'"
end
build_gem("platform_specific")

build_gem("platform_specific") do |s|
s.platform = Bundler.local_platform
s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 #{Bundler.local_platform}'"
end

# Build the exact same gem with a different name to compare using vs not using the option
build_gem("platform_specific_forced") do |s|
s.write "lib/platform_specific_forced.rb", "PLATFORM_SPECIFIC_FORCED = '1.0.0 RUBY'"
end
build_gem("platform_specific_forced")

build_gem("platform_specific_forced") do |s|
s.platform = Bundler.local_platform
s.write "lib/platform_specific_forced.rb", "PLATFORM_SPECIFIC_FORCED = '1.0.0 #{Bundler.local_platform}'"
end
end
end
Expand All @@ -34,8 +28,8 @@
gem "platform_specific"
G

expect(the_bundle).to include_gems "platform_specific_forced 1.0.0 RUBY"
expect(the_bundle).to include_gems "platform_specific 1.0.0 #{Bundler.local_platform}"
expect(the_bundle).to include_gems "platform_specific_forced 1.0 ruby"
expect(the_bundle).to include_gems "platform_specific 1.0 #{Bundler.local_platform}"
end

it "still respects a global `force_ruby_platform` config" do
Expand All @@ -46,8 +40,8 @@
gem "platform_specific"
G

expect(the_bundle).to include_gems "platform_specific_forced 1.0.0 RUBY"
expect(the_bundle).to include_gems "platform_specific 1.0.0 RUBY"
expect(the_bundle).to include_gems "platform_specific_forced 1.0 ruby"
expect(the_bundle).to include_gems "platform_specific 1.0 ruby"
end
end

Expand All @@ -56,13 +50,10 @@
build_repo4 do
build_gem("depends_on_platform_specific") {|s| s.add_dependency "platform_specific" }

build_gem("platform_specific") do |s|
s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 RUBY'"
end
build_gem("platform_specific")

build_gem("platform_specific") do |s|
s.platform = Bundler.local_platform
s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 #{Bundler.local_platform}'"
end
end
end
Expand All @@ -75,7 +66,7 @@
gem "platform_specific", :force_ruby_platform => true
G

expect(the_bundle).to include_gems "platform_specific 1.0.0 RUBY"
expect(the_bundle).to include_gems "platform_specific 1.0 ruby"
end
end

Expand All @@ -84,22 +75,17 @@
build_repo4 do
build_gem("depends_on_platform_specific") do |s|
s.add_dependency "platform_specific"
s.write "lib/depends_on_platform_specific.rb", "DEPENDS_ON_PLATFORM_SPECIFIC = '1.0.0 RUBY'"
end

build_gem("depends_on_platform_specific") do |s|
s.add_dependency "platform_specific"
s.platform = Bundler.local_platform
s.write "lib/depends_on_platform_specific.rb", "DEPENDS_ON_PLATFORM_SPECIFIC = '1.0.0 #{Bundler.local_platform}'"
end

build_gem("platform_specific") do |s|
s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 RUBY'"
end
build_gem("platform_specific")

build_gem("platform_specific") do |s|
s.platform = Bundler.local_platform
s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 #{Bundler.local_platform}'"
end
end
end
Expand All @@ -111,11 +97,11 @@
gem "depends_on_platform_specific", :force_ruby_platform => true
G

expect(the_bundle).to include_gems "depends_on_platform_specific 1.0.0 RUBY"
expect(the_bundle).to include_gems "platform_specific 1.0.0 #{Bundler.local_platform}"
expect(the_bundle).to include_gems "depends_on_platform_specific 1.0 ruby"
expect(the_bundle).to include_gems "platform_specific 1.0 #{Bundler.local_platform}"
end

it "reinstalls the ruby variant when a platform specific variant is already installed, the lockile has only RUBY platform, and :force_ruby_platform is used in the Gemfile" do
it "reinstalls the ruby variant when a platform specific variant is already installed, the lockile has only ruby platform, and :force_ruby_platform is used in the Gemfile" do
lockfile <<-L
GEM
remote: https://gem.repo4
Expand All @@ -140,7 +126,7 @@
gem "platform_specific", :force_ruby_platform => true
G

expect(the_bundle).to include_gems "platform_specific 1.0.0 RUBY"
expect(the_bundle).to include_gems "platform_specific 1.0 ruby"
end
end
end
8 changes: 4 additions & 4 deletions spec/bundler/install/gemfile/gemspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def x64_mingw_checksums(checksums)
G

bundle "update --bundler", artifice: "compact_index", verbose: true
expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 JAVA"
expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 java"
end

it "should evaluate the gemspec in its directory" do
Expand Down Expand Up @@ -461,7 +461,7 @@ def x64_mingw_checksums(checksums)

context "as a runtime dependency" do
it "keeps all platform dependencies in the lockfile" do
expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 RUBY"
expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 ruby"

checksums = checksums_section_when_existing do |c|
c.no_checksum "foo", "1.0"
Expand Down Expand Up @@ -502,7 +502,7 @@ def x64_mingw_checksums(checksums)
let(:platform_specific_type) { :development }

it "keeps all platform dependencies in the lockfile" do
expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 RUBY"
expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 ruby"

checksums = checksums_section_when_existing do |c|
c.no_checksum "foo", "1.0"
Expand Down Expand Up @@ -544,7 +544,7 @@ def x64_mingw_checksums(checksums)
let(:dependency) { "indirect_platform_specific" }

it "keeps all platform dependencies in the lockfile" do
expect(the_bundle).to include_gems "foo 1.0", "indirect_platform_specific 1.0", "platform_specific 1.0 RUBY"
expect(the_bundle).to include_gems "foo 1.0", "indirect_platform_specific 1.0", "platform_specific 1.0 ruby"

checksums = checksums_section_when_existing do |c|
c.no_checksum "foo", "1.0"
Expand Down
13 changes: 5 additions & 8 deletions spec/bundler/install/gemfile/platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
gem "platform_specific"
G

expect(the_bundle).to include_gems "platform_specific 1.0 JAVA"
expect(the_bundle).to include_gems "platform_specific 1.0 java"
end

it "pulls the pure ruby version on jruby if the java platform is not present in the lockfile and bundler is run in frozen mode", :jruby_only do
Expand All @@ -72,23 +72,20 @@
gem "platform_specific"
G

expect(the_bundle).to include_gems "platform_specific 1.0 RUBY"
expect(the_bundle).to include_gems "platform_specific 1.0 ruby"
end

context "on universal Rubies" do
before do
build_repo4 do
build_gem "darwin_single_arch" do |s|
s.platform = "ruby"
s.write "lib/darwin_single_arch.rb", "DARWIN_SINGLE_ARCH = '1.0 RUBY'"
end
build_gem "darwin_single_arch" do |s|
s.platform = "arm64-darwin"
s.write "lib/darwin_single_arch.rb", "DARWIN_SINGLE_ARCH = '1.0 arm64-darwin'"
end
build_gem "darwin_single_arch" do |s|
s.platform = "x86_64-darwin"
s.write "lib/darwin_single_arch.rb", "DARWIN_SINGLE_ARCH = '1.0 x86_64-darwin'"
end
end
end
Expand Down Expand Up @@ -158,7 +155,7 @@
gem "nokogiri"
G

expect(the_bundle).to include_gems "nokogiri 1.4.2 JAVA", "weakling 0.0.3"
expect(the_bundle).to include_gems "nokogiri 1.4.2 java", "weakling 0.0.3"

simulate_new_machine
bundle "config set --local force_ruby_platform true"
Expand All @@ -171,7 +168,7 @@
simulate_platform "java"
bundle "install"

expect(the_bundle).to include_gems "nokogiri 1.4.2 JAVA", "weakling 0.0.3"
expect(the_bundle).to include_gems "nokogiri 1.4.2 java", "weakling 0.0.3"
end

it "does not keep unneeded platforms for gems that are used" do
Expand Down Expand Up @@ -400,7 +397,7 @@

checksums.checksum gem_repo1, "platform_specific", "1.0"

expect(the_bundle).to include_gem "platform_specific 1.0 RUBY"
expect(the_bundle).to include_gem "platform_specific 1.0 ruby"

expect(lockfile).to eq <<~G
GEM
Expand Down
20 changes: 10 additions & 10 deletions spec/bundler/install/gemfile/specific_platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
end
end

it "understands that a non-platform specific gem in a new lockfile locked only to RUBY doesn't necessarily mean installing the non-specific variant" do
it "understands that a non-platform specific gem in a new lockfile locked only to ruby doesn't necessarily mean installing the non-specific variant" do
simulate_platform "x86_64-darwin-15" do
setup_multiplatform_gem

Expand Down Expand Up @@ -113,7 +113,7 @@
end
end

context "when running on a legacy lockfile locked only to RUBY" do
context "when running on a legacy lockfile locked only to ruby" do
around do |example|
build_repo4 do
build_gem "nokogiri", "1.3.10"
Expand Down Expand Up @@ -148,12 +148,12 @@
simulate_platform "arm64-darwin-22", &example
end

it "still installs the generic RUBY variant if necessary" do
it "still installs the generic ruby variant if necessary" do
bundle "install --verbose", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
expect(out).to include("Installing nokogiri 1.3.10")
end

it "still installs the generic RUBY variant if necessary, even in frozen mode" do
it "still installs the generic ruby variant if necessary, even in frozen mode" do
bundle "install --verbose", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s, "BUNDLE_FROZEN" => "true" }
expect(out).to include("Installing nokogiri 1.3.10")
end
Expand Down Expand Up @@ -459,7 +459,7 @@
expect(err).to include(error_message).once
end

it "does not generate a lockfile if RUBY platform is forced and some gem has no RUBY variant available" do
it "does not generate a lockfile if ruby platform is forced and some gem has no ruby variant available" do
build_repo4 do
build_gem("sorbet-static", "0.5.9889") {|s| s.platform = Gem::Platform.local }
end
Expand All @@ -480,7 +480,7 @@
ERROR
end

it "automatically fixes the lockfile if RUBY platform is locked and some gem has no RUBY variant available" do
it "automatically fixes the lockfile if ruby platform is locked and some gem has no ruby variant available" do
build_repo4 do
build_gem("sorbet-static-and-runtime", "0.5.10160") do |s|
s.add_dependency "sorbet", "= 0.5.10160"
Expand Down Expand Up @@ -558,7 +558,7 @@
L
end

it "automatically fixes the lockfile if both RUBY platform and a more specific platform are locked, and some gem has no RUBY variant available" do
it "automatically fixes the lockfile if both ruby platform and a more specific platform are locked, and some gem has no ruby variant available" do
build_repo4 do
build_gem "nokogiri", "1.12.0"
build_gem "nokogiri", "1.12.0" do |s|
Expand Down Expand Up @@ -632,7 +632,7 @@
L
end

it "automatically fixes the lockfile if only RUBY platform is locked and some gem has no RUBY variant available" do
it "automatically fixes the lockfile if only ruby platform is locked and some gem has no ruby variant available" do
build_repo4 do
build_gem("sorbet-static-and-runtime", "0.5.10160") do |s|
s.add_dependency "sorbet", "= 0.5.10160"
Expand Down Expand Up @@ -844,7 +844,7 @@
end
end

it "automatically fixes the lockfile if locked only to RUBY, and some locked specs don't meed locked dependencies" do
it "automatically fixes the lockfile if locked only to ruby, and some locked specs don't meed locked dependencies" do
simulate_platform "x86_64-linux" do
build_repo4 do
build_gem("ibandit", "0.7.0") do |s|
Expand Down Expand Up @@ -1119,7 +1119,7 @@
end
end

it "automatically fixes the lockfile when only RUBY platform locked, and adding a dependency with subdependencies not valid for RUBY" do
it "automatically fixes the lockfile when only ruby platform locked, and adding a dependency with subdependencies not valid for ruby" do
simulate_platform "x86_64-linux" do
build_repo4 do
build_gem("sorbet", "0.5.10160") do |s|
Expand Down
2 changes: 1 addition & 1 deletion spec/bundler/lock/lockfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@
G
end

it "adds compatible platform specific variants to the lockfile, even if resolution fallback to RUBY due to some other incompatible platform specific variant" do
it "adds compatible platform specific variants to the lockfile, even if resolution fallback to ruby due to some other incompatible platform specific variant" do
simulate_platform "arm64-darwin-23" do
build_repo4 do
build_gem "google-protobuf", "3.25.1"
Expand Down
Loading

0 comments on commit 1d97c46

Please sign in to comment.