Skip to content

Commit

Permalink
Leave ":" after MANPATH when not set
Browse files Browse the repository at this point in the history
So that system man pages still work after a gem with man pages overrides
it.
  • Loading branch information
deivid-rodriguez committed Nov 1, 2021
1 parent 3613737 commit 1031879
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bundler/lib/bundler/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def setup_manpath

return if manuals.empty?
Bundler::SharedHelpers.set_env "MANPATH", manuals.concat(
ENV["MANPATH"].to_s.split(File::PATH_SEPARATOR)
ENV["MANPATH"] ? ENV["MANPATH"].to_s.split(File::PATH_SEPARATOR) : [""]
).uniq.join(File::PATH_SEPARATOR)
end

Expand Down
71 changes: 49 additions & 22 deletions bundler/spec/runtime/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -745,41 +745,68 @@ def clean_load_path(lp)
expect(err).to be_empty
end

describe "$MANPATH" do
before do
context "when the user has `MANPATH` set", :man do
before { ENV["MANPATH"] = "/foo#{File::PATH_SEPARATOR}" }

it "adds the gem's man dir to the MANPATH" do
build_repo4 do
build_gem "with_man" do |s|
s.write("man/man1/page.1", "MANPAGE")
end
end

install_gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem "with_man"
G

run "puts ENV['MANPATH']"
expect(out).to eq("#{default_bundle_path("gems/with_man-1.0/man")}#{File::PATH_SEPARATOR}/foo")
end
end

context "when the user has one set" do
before { ENV["MANPATH"] = "/foo#{File::PATH_SEPARATOR}" }
context "when the user does not have `MANPATH` set", :man do
before { ENV.delete("MANPATH") }

it "adds the gem's man dir to the MANPATH" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem "with_man"
G
it "adds the gem's man dir to the MANPATH, leaving : in the end so that system man pages still work" do
build_repo4 do
build_gem "with_man" do |s|
s.write("man/man1/page.1", "MANPAGE")
end

run "puts ENV['MANPATH']"
expect(out).to eq("#{default_bundle_path("gems/with_man-1.0/man")}#{File::PATH_SEPARATOR}/foo")
build_gem "with_man_overriding_system_man" do |s|
s.write("man/man1/ls.1", "LS MANPAGE")
end
end
end

context "when the user does not have one set" do
before { ENV.delete("MANPATH") }
install_gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem "with_man"
G

it "adds the gem's man dir to the MANPATH" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem "with_man"
G
run <<~RUBY
puts ENV['MANPATH']
require "open3"
puts Open3.capture2e("man", "ls")[1].success?
RUBY

run "puts ENV['MANPATH']"
expect(out).to eq(default_bundle_path("gems/with_man-1.0/man").to_s)
end
expect(out).to eq("#{default_bundle_path("gems/with_man-1.0/man")}#{File::PATH_SEPARATOR}\ntrue")

install_gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem "with_man_overriding_system_man"
G

run <<~RUBY
puts ENV['MANPATH']
require "open3"
puts Open3.capture2e("man", "ls")[0]
RUBY

lines = out.split("\n")

expect(lines).to include("#{default_bundle_path("gems/with_man_overriding_system_man-1.0/man")}#{File::PATH_SEPARATOR}")
expect(lines).to include("LS MANPAGE")
end
end

Expand Down
1 change: 1 addition & 0 deletions bundler/spec/support/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def inspect
config.filter_run_excluding :readline => Gem.win_platform?
config.filter_run_excluding :jruby => RUBY_ENGINE != "jruby"
config.filter_run_excluding :truffleruby => RUBY_ENGINE != "truffleruby"
config.filter_run_excluding :man => Gem.win_platform?

config.filter_run_when_matching :focus unless ENV["CI"]
end

0 comments on commit 1031879

Please sign in to comment.